更新到23.3.0后Android支持库错误

Non*_*hoi 47 android android-support-library

我一直在使用android支持v4 23.1.1,并且最近尝试将其更新为23.3.0(这是被问到的最新版本)但是我收到以下错误:

错误:与依赖项"com.android.support:support-annotations"冲突.
app(23.3.0)和测试app(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'
Run Code Online (Sandbox Code Playgroud)

以前所有的版本都是23.1.1,它更新后发生错误很好

编辑:

Gradle Version 2.10
Gradle Plugin Version 2.0.0
buildToolsVersion "23.0.3"
Run Code Online (Sandbox Code Playgroud)

Non*_*hoi 101

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

androidTestCompile 'com.android.support:support-annotations:23.3.0'
Run Code Online (Sandbox Code Playgroud)

它解决了我的问题.

更新:

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

  • 尝试添加androidTestCompile'c​​om.android.support:support-v4:23.4.0' (3认同)
  • SO - 堆栈溢出 (3认同)

小智 50

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

将其添加到您的gradle文件中.

configurations.all {
  resolutionStrategy {
    force 'com.android.support:support-annotations:23.1.1'
 }
}
Run Code Online (Sandbox Code Playgroud)

这解决了我的问题.

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

  • 如果它适用于杰克沃顿,它对我有用! (3认同)

Mar*_*arr 20

只是举例说明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'

}
Run Code Online (Sandbox Code Playgroud)

收到错误:

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

当我添加时固定:

androidTestCompile 'com.android.support:support-annotations:25.3.0'
Run Code Online (Sandbox Code Playgroud)

最终文件:

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'
}
Run Code Online (Sandbox Code Playgroud)


MAN*_*ANN 10

我的orignal 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'
}
Run Code Online (Sandbox Code Playgroud)

导致以下错误:
错误:与依赖项"com.android.support:support-annotations"冲突.app(23.4.0)和测试app(22.2.0)的已解决版本有所不同.有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict.

在阅读错误提示的链接后,我找到了这些行:

运行检测测试时,主APK和测试APK共享相同的类路径.如果主APK和测试APK使用相同的库(例如Guava)但是在不同版本中,Gradle构建将失败.如果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'
}
Run Code Online (Sandbox Code Playgroud)

即使在上述更改后,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'
}
Run Code Online (Sandbox Code Playgroud)


Bri*_*ian 5

我花了一些时间来摆脱这个错误.但这对我有用,试一试:

注意:我使用的是compileSdkVersion 26

我删除了build.gradle中依赖项块中的androidTestImplementation'com.android.support.test:runner:1.0.2'和androidTestImplementation'com.android.support.test.espresso:espresso-core:3.0.2'. :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'
}
Run Code Online (Sandbox Code Playgroud)

我希望这会派上用场!