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

时间:2017-04-20 07:37:23

标签: android testing junit android-gradle dependencies

我试图解决两个错误:

  1. 无法解析符号' test'
  2. 无法解析符号' AndroidJUnit4'
  3. 在我的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'
    }
    

    这解决了这两个错误,但会出现警告:

      

    错误:与依赖关系冲突&junit:junit'在项目':app'。   app(4.11)和测试app(4.12)的已解决版本不同。

    谢谢!

3 个答案:

答案 0 :(得分:9)

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

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

android {
    configurations.all {
        resolutionStrategy.force 'junit:junit:4.11'
    }
}

答案 1 :(得分:1)

删除

testCompile 'junit:junit:4.11'

compile 'junit:junit:4.11'

[用compile编译替换testCompile]

答案 2 :(得分:-1)

有了您的问题,您可以尝试:

file>>project Structure>>app>>dependencies>>click button "+" >>library dependence>>input junit>>click junit 4.12>>done

好的