Android support library error after updating to 23.3.0

后端 未结 13 646
南笙
南笙 2020-11-30 02:28

I have been using android support v4 23.1.1 and recently tried to update it to 23.3.0 ( the latest one when this was asked) but I got the following error:

相关标签:
13条回答
  • 2020-11-30 02:54

    It was solved after adding the last line:

    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'
    compile 'com.android.support:support-annotations:27.1.1'}
    
    0 讨论(0)
  • 2020-11-30 02:55

    For those people who are still facing this problem just add this line to your dependencies.

    androidTestCompile 'com.android.support:support-annotations:23.3.0'
    

    It solved my problem.

    UPDATE:

    If you have this error nowadays, you can just insert the new versioncode (23.3.0 in this case, or 27.1.1 in May '18) as it is described in the error into the above described solution.

    0 讨论(0)
  • 2020-11-30 02:57
    1. Open Android Studio

    2. Navigate to Project > Gradle Scripts > build.gradle (Module:app)

    3. Add dependencies {androidTestCompile 'com.android.support:support-annotations:xx.x.x'}

    4. You can replace xx.x.x to version which is showing in an error

    5. Save Gradle script

    6. Build Project

    Hope this will work! :)

    0 讨论(0)
  • remove test dependency from build.gradel file for resolving the issues

    0 讨论(0)
  • 2020-11-30 02:58

    You have to use the same version for app and androidTest APKs. To do this, specify the same version as your app,

    androidTestCompile 'com.android.support:support-annotations:24.1.1'
    

    where 24.1.1 is the version number of the dependency used in your app

    0 讨论(0)
  • 2020-11-30 02:59

    My orignal app.gradle had:

    dependencies {
        // App dependencies
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.4.0' 
    
        // Testing-only dependencies
        androidTestCompile 'com.android.support.test:runner:0.3'
        androidTestCompile 'com.android.support.test:rules:0.3'
        androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
    }
    

    which resulted in following error:
    Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (22.2.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

    After reading the link suggested in error, I found theses lines:

    When instrumentation tests are run, both the main APK and test APK share the same classpath. Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions. If gradle didn't catch that, your app could behave differently during tests and during normal run (including crashing in one of the cases).

    So I modified my app.gradle dependencies to:

    dependencies {
        // App dependencies
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.4.0'
    
        // Testing-only dependencies
        androidTestCompile 'com.android.support:support-annotations:23.3.0'
        androidTestCompile 'com.android.support.test:runner:0.3'
        androidTestCompile 'com.android.support.test:rules:0.3'
        androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
    }
    

    Even after the above change gradle was not happy :-(:
    Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (23.3.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

    Change in test apk version was different! So I modified the version string as pasted below which worked for me:

    (Nirvana)

    dependencies {
        // App dependencies
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.4.0' // main APK
    
        // Testing-only dependencies
        androidTestCompile 'com.android.support:support-annotations:23.4.0' //test APK
        androidTestCompile 'com.android.support.test:runner:0.3'
        androidTestCompile 'com.android.support.test:rules:0.3'
        androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
    }
    
    0 讨论(0)
提交回复
热议问题