2

I created a new project as usual andafter the gradle running I get this error: `Error:Execution failed for task ':app:preDebugAndroidTestBuild'.

Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.`

This is my fresh project gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.elili.deltacalculator"
    minSdkVersion 18
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

I have zero ideas on how to fix it...

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Eli Kozinets
  • 117
  • 1
  • 9

2 Answers2

3

If you are not going to implement testing code, then remove junit from your app. You can replace your gradle by below.

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.elili.deltacalculator"
    minSdkVersion 18
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
0

You need to try the annotation library using:

androidTestCompile 'com.android.support:support-annotations:26.1.0'

First way, It use like this:

Force to use support annotations in the test app, so it is internally used by the runner module.

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.android.support:appcompat-v7:26.1.0'
    .
    .
    .
    .
    androidTestCompile 'com.android.support:support-annotations:26.1.0'

}

Second way is to use this as:

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
}
Janvi Vyas
  • 732
  • 5
  • 16