【问题标题】:Android support library error after updating to 23.3.0更新到 23.3.0 后 Android 支持库错误
【发布时间】:2016-04-25 06:41:53
【问题描述】:

我一直在使用 android support v4 23.1.1,最近尝试将其更新到 23.3.0(被问到时的最新版本),但出现以下错误:

错误:与依赖项“com.android.support:support-annotations”冲突。
应用 (23.3.0) 和测试应用 (23.1.1) 的已解决版本不同。
详情请见http://g.co/androidstudio/app-test-app-conflict

到目前为止,我已经找到了这个https://code.google.com/p/android/issues/detail?id=206137

我访问了这两个链接,但我无法解决我的问题,我该如何解决这个问题?

编辑:

我的依赖项中有这些

compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.android.support:design:23.3.0'

以前所有版本都是23.1.1 并且运行良好,更新后出现错误

编辑:

Gradle Version 2.10
Gradle Plugin Version 2.0.0
buildToolsVersion "23.0.3"

【问题讨论】:

  • 你能发布你的gradle设置内容吗?
  • @Raptor 我已经更新了问题
  • 他的意思是添加 buildToolsVersion
  • @mehrdadkhosravi buildToolsVersion "23.0.3"
  • 请发布完整的设置内容。 buildToolsVersion、Gradle 版本和 Android Studio 版本是什么?我正在使用 23.3.0buildToolsVersion 23.0.2 ,工作正常。

标签: android android-support-library


【解决方案1】:

对于那些仍然面临这个问题的人,只需将此行添加到您的依赖项中。

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

它解决了我的问题。

更新:

如果您现在遇到此错误,您只需将新版本代码(在这种情况下为 23.3.0,或在 18 年 5 月中为 27.1.1)插入上述解决方案中的错误中。

【讨论】:

  • 尝试了你的解决方案,但仍然遇到错误:Error:Conflict with dependency 'com.android.support:support-v4'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details. Gradle 依赖项:androidTestCompile 'com.android.support:support-annotations:23.4.0' 你能建议吗?
  • 尝试添加 androidTestCompile 'com.android.support:support-v4:23.4.0'
  • 仍然给我留下了Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.。但是在添加 androidTestCompile 'com.android.support:appcompat-v7:23.4.0' 会导致 values.xml 中出现错误 Error:(72) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'. ...
  • SO - 堆栈内存溢出
  • 糟糕,我的错。谢谢
【解决方案2】:

对于那些仍然面临问题的人,以上答案在 android studio 2.2 Preview 中对我没有帮助。

将此添加到您的 gradle 文件中。

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

这解决了我的问题。

参考: https://github.com/JakeWharton/u2020/blob/05a57bf43b9b61f16d32cbe8717af77cd608b0fb/build.gradle#L136-L140

【讨论】:

  • 似乎也修复了我的问题,在 AS 2.2 Preview 3 中
【解决方案3】:

只是举例说明 Akshayraj 的回答

原始 Gradle 文件:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    [...]

    compile 'com.android.support:support-annotations:25.3.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

}

收到错误:

错误:与项目 ':app' 中的依赖项 'com.android.support:support-annotations' 冲突。
应用 (25.1.0) 和测试应用 (23.1.1) 的已解决版本不同。
有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict。 "

已修复当我添加时:

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

最终文件:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    [...]

    compile 'com.android.support:support-annotations:25.3.0'

    androidTestCompile 'com.android.support:support-annotations:25.3.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}

【讨论】:

    【解决方案4】:

    我原来的 app.gradle 有:

    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'
    }
    

    导致以下错误:
    错误:与依赖项“com.android.support:support-annotations”冲突。应用程序 (23.4.0) 和测试应用程序 (22.2.0) 的已解决版本不同。详情请参阅http://g.co/androidstudio/app-test-app-conflict

    在阅读了错误提示的链接后,我发现了以下几行:

    运行仪器测试时,主 APK 和测试 APK 共享相同的类路径。如果主 APK 和 测试 APK 使用相同的库(例如 Guava),但使用不同的库 版本。如果 gradle 没有捕捉到这一点,您的应用程序可能会运行 在测试期间和正常运行期间(包括在 一种情况)。

    所以我修改了我的 app.gradle 依赖项:

    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'
    }
    

    即使在上述更改之后,gradle 也不满意 :-(:
    错误:与依赖项 'com.android.support:support-annotations' 冲突。应用程序 (23.4.0) 和测试的已解决版本应用(23.3.0)不同。详情请参阅http://g.co/androidstudio/app-test-app-conflict

    测试 apk 版本的变化是不同的!所以我修改了下面粘贴的版本字符串,这对我有用:

    (涅槃)

    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'
    }
    

    【讨论】:

    • 一个关于 android gradle 使用的好例子 --> github.com/JakeWharton/u2020/blob/master/build.gradle
    • 不幸的是,它对我不起作用,但我明白你的答案是如何起作用的。 +1 解释。
    • 谢谢!这是我一直在寻找的答案。解释得很好。
    • 没有其他答案对我有用,但这个有用。谢谢;)
    【解决方案5】:

    我花了一段时间才摆脱这个错误。但这对我有用,试一试:

    注意:我使用的是 compileSdkVersion 26

    我删除了两个 androidTestImplementation 'com.android.support.test:runner:1.0.2' & androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 在 build.gradle(Module: app) 的依赖项块中。所以我最终得到了这个:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        buildToolsVersion '26.0.2'
        defaultConfig {
            applicationId "com.date.brian.cradletest"
            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'
        compile 'com.android.support:design:26.1.0'
        compile 'com.android.support:cardview-v7:26.1.0'
        compile 'com.android.support:recyclerview-v7:26.1.0'
        compile 'com.getbase:floatingactionbutton:1.9.0'
        compile 'de.hdodenhof:circleimageview:2.1.0'
        testImplementation 'junit:junit:4.12'
    }
    

    我希望这会派上用场!

    【讨论】:

    • 感谢它对我的帮助
    • 嗨,兄弟,很高兴它有帮助
    【解决方案6】:

    您必须为 app 和 androidTest APK 使用相同的版本。为此,请指定与您的应用相同的版本,

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

    其中 24.1.1 是您的应用中使用的依赖项的版本号

    【讨论】:

      【解决方案7】:
      compile 'com.android.support:design:24.1.1'
      

      【讨论】:

        【解决方案8】:

        对我来说,构建工具版本必须与依赖版本保持一致。所以假设构建工具版本是26.1.0,Gradle 依赖版本必须服从它。

        最简单的方法是创建一个版本变量并使用它。请参阅下面的示例

        ext {
            buildVersion = '26.1.0'
        }
        
        dependencies {
            compile "com.android.support:appcompat-v7:${buildVersion}"
        }
        

        【讨论】:

          【解决方案9】:

          只排除“注释”。不会造成任何伤害

          androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
              exclude group: 'com.android.support', module: 'support-annotations'
          })
          

          【讨论】:

            【解决方案10】:
            1. 打开Android Studio

            2. 导航到 项目 > Gradle 脚本 > build.gradle (Module:app)

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

            4. 您可以将 xx.x.x 替换为出现错误的版本

            5. 保存 Gradle 脚本

            6. 构建项目

            希望这会奏效! :)

            【讨论】:

              【解决方案11】:

              添加最后一行后解决:

              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'}
              

              【讨论】:

                【解决方案12】:

                从 build.gradel 文件中删除测试依赖项以解决问题

                【讨论】:

                  【解决方案13】:
                  /*
                  Resolves dependency versions across test and production APKs, specifically, transitive
                  dependencies. This is required since Espresso internally has a dependency on support-annotations.
                  */
                  configurations.all {
                      resolutionStrategy.force "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
                  }
                  

                  【讨论】:

                  • 虽然此代码可能会回答问题,但提供有关 如何 和/或 为什么 解决问题的附加 context 将改善答案的长度长期价值。提及为什么这个答案比其他答案更合适也没有什么坏处。
                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2016-06-08
                  • 1970-01-01
                  • 1970-01-01
                  • 2016-07-26
                  相关资源
                  最近更新 更多