无法解决 Gradle 中的 Mockito 依赖项

tro*_*tto 1 testing android unit-testing mockito gradle

虽然我看到两个不同的帖子带有此错误消息,但对我没有任何作用:

错误:(25, 17) 无法解决:org.mockito:mockito-core:1.10.19

我尝试使用 compile、androidTestCompile 和 testCompile 更改 Mockito 依赖项,并且在全局 Gradle 文件中我尝试将 Maven 添加为存储库,但没有成功。

编辑:我使用的是 Android Studio 2.1

这是我的应用程序 build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
    applicationId "ivano.android.com.mockitoexample"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'

}
Run Code Online (Sandbox Code Playgroud)

这是全球的

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

tro*_*tto 5

我找到了解决方案。在大部分教程中都是为了添加mockito-core而编写的。而是添加 mockito-all 解决了我的问题,使 gradle 编译没有错误