警告:与项目':app'中的依赖项'junit:junit'冲突.app(4.11)和test app(4.12)的已解决版本

Car*_*ada 4 testing junit dependencies android android-gradle-plugin

我正在尝试解决两个错误:

  1. 无法解析符号'test'
  2. 无法解析符号'AndroidJUnit4'

在我的Android Studio项目中运行集成测试.为了解决这个问题,我已经看到了一些答案,我的build.gradle看起来像:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.ps.comunio.comuniops"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    compileOptions.with {
        sourceCompatibility = JavaVersion.VERSION_1_7
        targetCompatibility = JavaVersion.VERSION_1_7
    }
    lintOptions {
        abortOnError false
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.11'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'info.cukes:cucumber-java:1.2.0'
    compile 'info.cukes:cucumber-junit:1.2.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}
Run Code Online (Sandbox Code Playgroud)

这样可以解决这两个错误,但会出现警告:

错误:与项目':app'中的依赖项'junit:junit'冲突.app(4.11)和测试app(4.12)的已解决版本有所不同.

谢谢!

Saf*_*wan 9

一种解决方案是强制Gradle编译junit:junit:4.11而不是junit:junit:4.12

为此,请在您的应用中build.gradle添加以下内容:

android {
    configurations.all {
        resolutionStrategy.force 'junit:junit:4.11'
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 -1

针对您的问题,您可以尝试:

file>>project Structure>>app>>dependencies>>click button "+" >>library dependence>>input junit>>click junit 4.12>>done
Run Code Online (Sandbox Code Playgroud)

好的