Warning: conflict with dependency "junit: junit" in project "application". Resolved versions for app (4.11) and test app (4.12)

I am trying to resolve two errors:

  • Cannot resolve symbol 'test'
  • Cannot resolve symbol "AndroidJUnit4"

Running integration tests in my Android Studio project. To solve this problem I've seen several answers and my build.gradle looks like this:

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'
}

      

This will resolve both errors, but a warning appears:

Error: Conflict with dependency "junit: junit" in project "application". The allowed versions for apps (4.11) and test app (4.12) are different.

Thank!

+3


source to share


3 answers


One solution is to force Gradle to compile junit:junit:4.11

insteadjunit:junit:4.12

To do this, build.gradle

add the following in the application :



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

      

+5


source


With your problem, you can try:

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

      



OK

-1


source


Delete

testCompile 'junit:junit:4.11'

      

from

compile 'junit:junit:4.11'

      

[replace testCompile with compilation]

-1


source







All Articles