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 1455
臣服心动
臣服心动 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 05:53

    If you use version 26 then inside dependencies version should be 1.0.1 and 3.0.1 i.e., as follows

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

    If you use version 27 then inside dependencies version should be 1.0.2 and 3.0.2 i.e., as follows

      androidTestImplementation 'com.android.support.test:runner:1.0.2'
      androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    
    0 讨论(0)
  • 2020-12-02 05:53

    This is due a conflict of versions, to solve it, just force an update of your support-annotations version, adding this line on your module: app gradle

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

    Hope this solves your issue ;)

    Edit

    Almost forgot, you can declare a single extra property (https://docs.gradle.org/current/userguide/writing_build_scripts.html#sec:extra_properties) for the version, go to your project (or your top) gradle file, and declare your support, or just for this example, annotation version var

    ext.annotation_version = "27.1.1"

    Then in your module gradle replace it with:

    implementation ("com.android.support:support-annotations:$annotation_version")

    This is very similar to the @emadabel solution, which is a good alternative for doing it, but without the block, or the rootproject prefix.

    0 讨论(0)
  • 2020-12-02 05:53

    Don't worry It is simple:

    Go to the "Project" Directory structure and in that go to "Gradle Scripts" and inside it go to "build.gradle (Module:app)" and double click it.

    Now - Scroll down the program and in that go to the dependencies section : Like below


    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'
    

    }


    Now in this Delete the last two lines of code and rebuild the app and now it will work

    The dependencies should be:


    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'
    

    }


    REBUILD THE APP AND IT WORKS !!

    0 讨论(0)
  • 2020-12-02 05:53

    Go to the build.gradle(Module App) in your project:

    Follow the pic and change those version:

    compileSdkVersion: 27
    targetSdkVersion: 27
    

    and if android studio version 2: Change the line with this line:

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

    else Change the line with this line:

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

    and hopefully, you will solve your bug.

    0 讨论(0)
  • 2020-12-02 05:54

    Add this to your gradle file.

    implementation 'com.android.support:support-annotations:27.1.1'
    
    0 讨论(0)
  • 2020-12-02 05:55

    Add the below line in your app.gradle file before depencencies block.

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

    There's also screenshot below for a better understanding.

    1. the configurations.all block will only be helpful if you want your target sdk to be 26. If you can change it to 27 the error will be gone without adding the configuration block in app.gradle file.

    2. There is one more way if you would remove all the test implementation from app.gradle file it would resolve the error and in this also you dont need to add the configuration block nor you need to change the targetsdk version.

    Hope that helps.

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