15

Getting the below error at the time of running java program in android studio.

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.

Any solution please. ?

Kms
  • 1,082
  • 2
  • 11
  • 27
  • For this you have to take a look at your dependencies and make sure that there are none of these conflicts. If you would like us to help you it will help to post your dependencies. – creativecreatorormaybenot Apr 29 '18 at 17:34
  • I'm having the same problem. This is ridiculous. **It's a fresh new project.** Why would this happen?! Android Studio 3.0.1 – Alaa M. Mar 11 '19 at 05:53

14 Answers14

27

Use implementation 'com.android.support:appcompat-v7:27.1.1' instead of implementation 'com.android.support:appcompat-v7:26.1.0' and change compileSdkVersion 26 to 27

Nazmus Saadat
  • 973
  • 9
  • 22
22

thanks to @Ganesh Bhat and Chad Bingham

For those who still facing the problem, above answer did not help me in android studio 2.2 Preview.

This fixed my issue.

add this to your gradle file.

configurations.all {
  resolutionStrategy {
    force 'com.android.support:support-annotations:23.1.1'
 }
}

Reference: https://github.com/JakeWharton/u2020/blob/05a57bf43b9b61f16d32cbe8717af77cd608b0fb/build.gradle#L136-L140

Android support library error after updating to 23.3.0

Resolved versions for app (22.0.0) and test app (21.0.3) differ


update - if the previous answer doesn't work :

you should update the compileSdkVersion and appcompat to the latest update till now compileSdkVersion is 27 , also appcompat is 27.1.1 and 28.0.0-alpha1 is a pre-release version

thus

change

compileSdkVersion 27

the attached photo will help you

and

implementation 'com.android.support:appcompat-v7:26.1.0'

to latest update

implementation 'com.android.support:appcompat-v7:27.1.1'

you can check the latest updates from this link :

https://developer.android.com/topic/libraries/support-library/revisions

Community
  • 1
  • 1
mahmoud zaher
  • 544
  • 6
  • 9
2

I answered before some minutes same question Reference. If you are not going to implement testing code, then remove junit from your app.

There are lot of other questions related to this.

Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.3.0) and test app (23.1.1) differ

Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.1.0) and test app (23.0.1) differ

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
2

Add this to your app gradle file

configurations.all {
   resolutionStrategy {
      force 'com.android.support:support-annotations:26.1.0'
   }
}
Mohammed mansoor
  • 743
  • 3
  • 11
  • 18
1

Add these lines within your app dependencies braces,

android{
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
    }
}

Latest is 27.1.1 upto this date.

Ashana.Jackol
  • 3,064
  • 28
  • 22
1

AS configuration version:

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
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'**

Modify:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.0.0-beta1'
testImplementation 'junit:junit:4.12'
**androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'**
Anandharaj R
  • 169
  • 1
  • 6
1

Well, I too faced the same problem here is how I fixed it

  • Goto app level Gradle file

There you will find what are all the config's you have set up. In my case here

android{
    **compileSdkVersion 26**
    defaultConfig {
        applicationId "com.xxxxxxxxxxx.yyyyyyyy.zzz"
        minSdkVersion 19
        **targetSdkVersion 26**
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

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

So here just change the compileSdkVersion & targetSdkVersion from 26 to 27 and

from dependencies change support appcomat

from   implementation 'com.android.support:appcompat-v7:26.1.0' 
to     implementation 'com.android.support:appcompat-v7:27.1.1'


android {
    **compileSdkVersion 27**
    defaultConfig {
        applicationId "com.xxxxxxxxxxx.yyyyyyyy.zzz"
        minSdkVersion 19
        **targetSdkVersion 27**
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    **implementation 'com.android.support:appcompat-v7:27.1.1'**
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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'
}

Got Fixed !!!

0

Hello guys I had the same problem for solving this problem u need to change you appcompat in your app bulid gradle to

implementation 'com.android.support:appcompat-v7:27.1.1'

then it should ask you to instal it if u have'nt installed if still errore didnt solved change your sdkversions it will help alot because if u change the appcompact to 27.1.1 u need to change your sdkversion to 27 as well i suggest all of u to update your android studio and the sdk to the lastest

0

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 due to there is no dependency added to your App build.gradle or might be its an old version. So, add a dependency for annotation support.

implementation 'com.android.support:support-annotations:27.1.1'

Here I have added annotation version 27.1.1 to solve your error if this is mismatched with different version then change it to the required version.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Ready Android
  • 3,529
  • 2
  • 26
  • 40
0

Try below change if it helps you

com.android.support:appcompat-v7:26.1.0

to

com.android.support:appcompat-v7:27.1.1

deadpool
  • 3
  • 1
  • 6
  • This exception usually thrown at time of appcompat version and compile version is not same try to make both are on same version. – deadpool Sep 04 '18 at 08:32
0

I found this very easy.

We will use update and use same version for all modules.

1. Go to project level build.gradle, use global variables

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

buildscript {
    ext.kotlinVersion = '1.2.61'

    ext.global_minSdkVersion = 16
    ext.global_targetSdkVersion = 28
    ext.global_buildToolsVersion = '28.0.1'
    ext.global_supportLibVersion = '27.1.1'
}

2. Go to app level build.gradle, and use global variables

app level build.gradle

android {
    compileSdkVersion global_targetSdkVersion
    buildToolsVersion global_buildToolsVersion
    defaultConfig {
        minSdkVersion global_minSdkVersion
        targetSdkVersion global_targetSdkVersion
}
...

dependencies {
    implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
    implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
    // and so on...
}

some library/module build.gradle

android {
    compileSdkVersion global_targetSdkVersion
    buildToolsVersion global_buildToolsVersion
    defaultConfig {
        minSdkVersion global_minSdkVersion
        targetSdkVersion global_targetSdkVersion
}
...

dependencies {
    implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
    implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
    // and so on...
}

The solution is to make your versions same as in all modules. So that you don't have conflicts.

Tips for future

I felt when I have updated versions of everything- gradle, sdks, libraries etc. then I face less errors. Because developers are working hard to make it easy development on Android Studio.

Always have **latest but stable versions** Unstable versions are alpha, beta and rc, ignore them in developing.

I have updated all below in my projects, and feel flawless coding.

Happy coding! :)

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
0

its important to take a look at this too, in your gradle

targetSdkVersion 27
compileSdkVersion 27
buildToolsVersion '27.0.3'
dungu
  • 125
  • 1
  • 13
0

Auto Import Settings

Go to settings>editor> Then check those two boxes as displayed in the image. It should solve it without any issue.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Ayanfe
  • 1
-1

Add This Code to the bottom of build.gradle at app level. It will work...

configurations.all {
    resolutionStrategy.eachDependency{
        DependencyResolveDetails details ->
            def requested=details.requested
            if(requested.group=="com.android.support"){
            if(!requested.name.startsWith("multidex")){
                details.useVersion("26.0.1")
            }
        }
    }
}
SHISHIR
  • 321
  • 3
  • 4