Android更新到23.3.0后支持库报错
Android support library error after updating to 23.3.0
我一直在使用 android 支持 v4 23.1.1,最近尝试将其更新到 23.3.0(被问到时是最新版本),但出现以下错误:
Error:Conflict with dependency 'com.android.support:support-annotations'.
Resolved versions for app (23.3.0) and test app (23.1.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details.
到目前为止我已经找到这个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"
对于那些仍然面临这个问题的人,只需将这行添加到您的依赖项中。
androidTestCompile 'com.android.support:support-annotations:23.3.0'
它解决了我的问题。
更新:
如果你现在有这个错误,你可以插入新的版本代码(23.3.0
在这种情况下,或 27.1.1
在 18 年 5 月),如错误中所述描述的解决方案。
对于那些仍然面临问题的人,以上答案在 android studio 2.2 预览版中对我没有帮助。
将此添加到您的 gradle 文件中。
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.1.1'
}
}
这解决了我的问题。
我原来的 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。
阅读错误建议的link后,我发现了这些行:
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).
所以我将 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'
}
compile 'com.android.support:design:24.1.1'
您必须为应用和 androidTest APK 使用相同的版本。为此,请指定与您的应用相同的版本,
androidTestCompile 'com.android.support:support-annotations:24.1.1'
其中 24.1.1 是您应用中使用的依赖项的版本号
只是举例说明 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'
}
收到错误:
Error:Conflict with dependency 'com.android.support:support-annotations' in project ':app'.
Resolved versions for app (25.1.0) and test app (23.1.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details. "
FIXED 当我添加时:
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'
}
/*
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"
}
对我来说,构建工具版本必须与依赖版本保持一致。所以假设构建工具版本是 26.1.0
,Gradle 依赖版本必须遵守它。
最简单的方法是创建一个版本变量并使用它。请参阅下面的示例
ext {
buildVersion = '26.1.0'
}
dependencies {
compile "com.android.support:appcompat-v7:${buildVersion}"
}
打开Android工作室
导航至 项目 > Gradle 脚本 > build.gradle(模块:app)
添加dependencies {androidTestCompile 'com.android.support:support-annotations:xx.x.x'}
可以把xx.x.x替换成报错的版本
保存Gradle脚本
构建项目
希望这能奏效! :)
我花了一段时间才摆脱这个错误。但这对我有用,试一试:
注意: 我使用的是 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'
}
我希望这能派上用场!
添加最后一行后解决:
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'}
从 build.gradel 文件中删除测试依赖项以解决问题
只排除'annotations'。不会造成伤害
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
我一直在使用 android 支持 v4 23.1.1,最近尝试将其更新到 23.3.0(被问到时是最新版本),但出现以下错误:
Error:Conflict with dependency 'com.android.support:support-annotations'.
Resolved versions for app (23.3.0) and test app (23.1.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details.
到目前为止我已经找到这个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"
对于那些仍然面临这个问题的人,只需将这行添加到您的依赖项中。
androidTestCompile 'com.android.support:support-annotations:23.3.0'
它解决了我的问题。
更新:
如果你现在有这个错误,你可以插入新的版本代码(23.3.0
在这种情况下,或 27.1.1
在 18 年 5 月),如错误中所述描述的解决方案。
对于那些仍然面临问题的人,以上答案在 android studio 2.2 预览版中对我没有帮助。
将此添加到您的 gradle 文件中。
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.1.1'
}
}
这解决了我的问题。
我原来的 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。
阅读错误建议的link后,我发现了这些行:
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).
所以我将 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'
}
compile 'com.android.support:design:24.1.1'
您必须为应用和 androidTest APK 使用相同的版本。为此,请指定与您的应用相同的版本,
androidTestCompile 'com.android.support:support-annotations:24.1.1'
其中 24.1.1 是您应用中使用的依赖项的版本号
只是举例说明 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'
}
收到错误:
Error:Conflict with dependency 'com.android.support:support-annotations' in project ':app'.
Resolved versions for app (25.1.0) and test app (23.1.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details. "
FIXED 当我添加时:
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'
}
/*
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"
}
对我来说,构建工具版本必须与依赖版本保持一致。所以假设构建工具版本是 26.1.0
,Gradle 依赖版本必须遵守它。
最简单的方法是创建一个版本变量并使用它。请参阅下面的示例
ext {
buildVersion = '26.1.0'
}
dependencies {
compile "com.android.support:appcompat-v7:${buildVersion}"
}
打开Android工作室
导航至 项目 > Gradle 脚本 > build.gradle(模块:app)
添加
dependencies {androidTestCompile 'com.android.support:support-annotations:xx.x.x'}
可以把xx.x.x替换成报错的版本
保存Gradle脚本
构建项目
希望这能奏效! :)
我花了一段时间才摆脱这个错误。但这对我有用,试一试:
注意: 我使用的是 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'
}
我希望这能派上用场!
添加最后一行后解决:
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'}
从 build.gradel 文件中删除测试依赖项以解决问题
只排除'annotations'。不会造成伤害
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})