1

Trying to follow the tutorial here: https://developer.android.com/training/basics/firstapp/creating-project

but after I create an activity and click "Finish" it gives a Gradle build error saying:

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.

Looking at other SO solutions (the second answer here: Resolved versions for app (22.0.0) and test app (21.0.3) differ) it said to add this to the dependencies on build.gradle script:

androidTestCompile 'com.android.support:support-annotations:xx.x.x'

The above solution is also what it shows on Google Samples (https://github.com/googlesamples/android-testing/blob/ba14ef9e925fa17621bf86abe5336dcb9d53e466/runner/AndroidJunitRunnerSample/app/build.gradle#L36)

So this is now my build.gradle (Module: app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.ahmedayman.ember"
        minSdkVersion 15
        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'
    androidTestCompile 'com.android.support:support-annotations:26.1.0'
}

but I'm still getting the same error when I try to sync the project. Any idea how to solve this?

SilentDev
  • 20,997
  • 28
  • 111
  • 214

4 Answers4

3

I had the same problem, I did some changes in build.gradle (Module: app) and it worked for me. I changed this androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

to: androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

it worked for me.

jonny
  • 313
  • 3
  • 12
  • Hi, thanks for the solution. It might solve the problem for others. What worked for me was following the documentation on the android website. See my answer for more information. (the error message actually provided a link which gave me a simple working solution). – SilentDev May 06 '18 at 20:21
2

I changed my implementation version for appcompat-v7 to 27.1.1 in build.gradle (Module:app) and it solved the problem for me.

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'
}
nijfranck
  • 21
  • 2
0

Edit

The answer here: All com.android.support libraries must use the exact same version specification

mentions that android studio 3.0 replaced compile with implementation, so I used implementation 'com.android.support:design:27.1.1' instead of compile (which is mentioned below).

Original Answer

The error message provided a link to a website to view. I viewed the website and the website linked to this URL: https://developer.android.com/studio/build/gradle-tips#configure-project-wide-properties

The URL mentioned to configure project-wide properties. It said to add this in my build.gradle project file:

// This block encapsulates custom properties and makes them available to all
// modules in the project.
ext {
    // The following are only a few examples of the types of properties you can define.
    compileSdkVersion = 26
    // You can also use this to specify versions for dependencies. Having consistent
    // versions between modules can avoid behavior conflicts.
    supportLibVersion = "27.1.1"
    ...
}

and to add this in my build.gradle app file:

android {
  // Use the following syntax to access properties you define at the project level:
  // rootProject.ext.property_name
  compileSdkVersion rootProject.ext.compileSdkVersion
  ...
}
...
dependencies {
    compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    ...
}

This solved the problem.

SilentDev
  • 20,997
  • 28
  • 111
  • 214
0

replace jcenter() with mavenCentral() in repositories

  • It would be better if you provided the bit more explanation to the problem and the solution – Prabhu Sep 23 '18 at 18:18