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.

前端 未结 15 1457
臣服心动
臣服心动 2020-12-02 05:46

I am new to Android App Development. When I tried to create a new project,Android Project...the following message popped up..

Error:Execution failed for task \':app:

相关标签:
15条回答
  • 2020-12-02 06:17

    Another simple way to solve this problem is to edit your build.gradle (app):

    1. Go to android tag and change compileSdkVersion 26 to compileSdkVersion 27
    2. Go to defaultConfig tag and change targetSdkVersion 26 to targetSdkVersion 27
    3. Got to dependencies tag and change implementation 'com.android.support:appcompat-v7:26.1.0' to implementation 'com.android.support:appcompat-v7:27.1.1'
    0 讨论(0)
  • 2020-12-02 06:17

    If changing target sdk version doesn't help then if you have any dependency with version 3.0.2 then change it to 3.0.1.

    e.g change

    androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
    

    to

    androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.1'
    
    0 讨论(0)
  • 2020-12-02 06:19

    Important Update

    Go to project level build.gradle, define 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'
    }
    

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

    app 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 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.

    Important Tips

    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 I don't face these errors anymore.

    • Update Android Studio (Track release)
    • Project level build.gradle - classpath 'com.android.tools.build:gradle:3.2.0' (Track android.build.gradle release & this)
    • Have updated buildToolVersion (Track buildToolVersion release)
    • Have latest compileSdkVersion and targetSdkVersion Track platform release
    • Have updated library versions, because after above updates, its necessary. (@See How to update)

    Happy coding! :)

    0 讨论(0)
提交回复
热议问题