我一直在使用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'
以前所有版本都是23.1.1
,并且在更新
编辑:
Gradle Version 2.10
Gradle Plugin Version 2.0.0
buildToolsVersion "23.0.3"
答案 0 :(得分:101)
对于仍然面临此问题的人,只需将此行添加到您的依赖项中。
androidTestCompile 'com.android.support:support-annotations:23.3.0'
它解决了我的问题。
<强>更新强>
如果您现在遇到此错误,您只需插入新版本代码(在这种情况下为23.3.0
,或在5月'{8}中插入27.1.1
),因为错误描述在上述解决方案中。
答案 1 :(得分:50)
对于那些仍然面临问题的人,上面的回答并没有帮助我在android studio 2.2预览中。
将此内容添加到您的gradle文件中。
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.1.1'
}
}
这解决了我的问题。
答案 2 :(得分: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'
}
收到错误:
错误:与依赖项冲突&com.android.support:support-annotations&#39;在项目&#39;:app&#39;。
app(25.1.0)和测试app(23.1.1)的已解决版本不同 有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict。 &#34;
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'
}
答案 3 :(得分: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'
}
导致以下错误:
错误:与依赖项冲突&com.android.support:support-annotations&#39;。 app(23.4.0)和测试app(22.2.0)的已解决版本有所不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict 。
在阅读错误提示的链接后,我找到了这些行:
当运行仪器测试时,主APK和测试APK 共享相同的类路径。如果主APK和,Gradle构建将失败 测试APK使用相同的库(例如番石榴)但不同 版本。如果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&#39;。 app(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'
}
答案 4 :(得分: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'
}
我希望这会派上用场!
答案 5 :(得分:3)
你必须为app和androidTest APK使用相同的版本。为此,请指定与您的应用相同的版本,
androidTestCompile 'com.android.support:support-annotations:24.1.1'
其中24.1.1是您的应用中使用的依赖项的版本号
答案 6 :(得分:2)
compile 'com.android.support:design:24.1.1'
答案 7 :(得分:1)
对我来说,构建工具版本必须与依赖版本保持一致。因此,假设构建工具版本为26.1.0
,Gradle依赖版本必须遵守它。
最简单的方法是创建一个版本变量&amp;用它。请参阅下面的示例
ext {
buildVersion = '26.1.0'
}
dependencies {
compile "com.android.support:appcompat-v7:${buildVersion}"
}
答案 8 :(得分:1)
只需排除'注释'即可。不会造成伤害
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
答案 9 :(得分:0)
打开 Android Studio
导航至项目&gt; Gradle Scripts&gt; build.gradle(模块:app)
添加dependencies {androidTestCompile 'com.android.support:support-annotations:xx.x.x'}
您可以将 xx.x.x 替换为错误中显示的版本
保存Gradle脚本
构建项目
希望这会奏效! :)
答案 10 :(得分:0)
添加最后一行后解决了这个问题:
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'}
答案 11 :(得分:-1)
/*
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"
}