0

I am using android studio 3.0.1 after I created New Project It will give below 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 app level build.gradle file

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 26
        defaultConfig {

            minSdkVersion 19
            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: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'
    }

and this is my top level build.gradle file

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

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

as per this post: Error While creating new project with android studio 3.0.1

I Changed my

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

to

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

but as I am using

targetSdkVersion 26

I should not use support library 27.1.1.

How can I resolve this issue

Any help accepted. Thank you :)

Kruti Parekh
  • 1,271
  • 9
  • 21
Learning Always
  • 1,563
  • 4
  • 29
  • 49
  • Here you have multiple same dependency issue , try to exclude one. – Koustuv Ganguly May 29 '18 at 04:41
  • 1
    `targetSdkVersion` has nothing to do with your support library versions. Support library versions are related to `compileSdkVersion`. If `compileSdkVersion` is `26` then support library version should be 26.x.x and if it is `27` then support library version should be 27.x.x – Kruti Parekh May 29 '18 at 04:47

5 Answers5

2

This is occur due to conflict the multiple library you have added in Gradle file.IF your target version is 26 then you must have to use library for 26 API version. Just go in Project structure -> .idea -> libraries -> remove the folder. Restart the android studio or Rebuild and clean the project. Problem will solve do this.

Google
  • 2,183
  • 3
  • 27
  • 48
  • @Learning Always Please accept the answer if it is helpful to you. so another user can follow this steps. Thanks – Google May 29 '18 at 05:52
1

You need to ensure compileSdkVersion is 27.

You need to exclude support library from espresso-Core as follows:

 androidTestImplementation('com.android.support.test.espresso:espresso- 
    core:3.0.2') {
        exclude group: 'com.android.support', module: 'support-annotations'
 }
Sagar
  • 23,903
  • 4
  • 62
  • 62
0

It all depends on your targetSdkVersion vesion. If its is 26 you should use implementation 'com.android.support:appcompat-v7:26.1.0' and if it is 27 you should go with implementation 'com.android.support:appcompat-v7:27.1.1'. After that sync the project and if not working try to clean and rebuild the project.

Raj
  • 2,997
  • 2
  • 12
  • 30
0

Try adding this at the bottom of build.gradle (app level one)

configurations.all {
    resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.1.0'
            }
        }
    }

}

Credit to Eugen Pechanec

Manohar
  • 22,116
  • 9
  • 108
  • 144
0

If you are using the support library version as 27.

com.android.support:appcompat-v7:27.1.1

Change to

targetSdkVersion 27
compileSdkVersion 27

I think it will solve your answer

Corrupt
  • 313
  • 4
  • 16