可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
This is the full error-
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
I know that there are a lot of solutions to this type of answers but I am an absolute beginner in android studio and I couldnt understand those solutions like the command line interface interacting with gradle and so on...
I was looking for a simple solution to this problem if there is.
Thanks a lot!
回答1:
Change all the implementation in your build gradle app
For Example.
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-annotations:27.1.1'
Change It all to latest version(27.1.1) and sync the project.
回答2:
Recently I was getting this error again....I just go to build->rebuild project and it works everytime for me.
回答3:
configurations.all{
resolutionStrategy {
force 'com.android.support:support-annotations:26.1.0'
}
}
回答4:
Modify below line in gradle file.
//From
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//To
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
回答5:
This is the type of bug that really makes me resent Android Studio.
But anyway, the solution for me was quite simple: Edit the app.iml
and change the com.android.support:support-annotations
version. In this case it's easy to find, simply ctrl+F
and type "27.1.1" (it should be the only hit) and change to your version "26.1.0".
In other words, change it from
<orderEntry type="library" scope="TEST" name="com.android.support:support-annotations:27.1.1@jar" level="project" />
to
<orderEntry type="library" scope="TEST" name="com.android.support:support-annotations:26.1.0@jar" level="project" />
Afterwards, rebuild the project. (simply rebuilding it wasn't working for me until i edited the app.iml
)
回答6:
its requires just few steps...
1. Go to module.app file.
2. Change your target sdk version and compile sdk version to latest version ( here it is 27)
3.then change appcompact version to 27.1.1
4. Sync gradle file
回答7:
Go to build.gradle(Module:app) file, add compile 'com.android.support:support-annotations:27.1.1'
into dependencies, then click 'sync now' again.
回答8:
Use
implementation 'com.android.support:appcompat-v7:27.1.1'
instead of
implementation 'com.android.support:appcompat-v7:26.1.1'
and change compileSdkVersion 26 to 27
回答9:
Your root gradle file should contains:
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
jcenter()
google ()
}
}
And the module gradle file should contains libraries like:
buildscript {
repositories {
jcenter()
mavenCentral()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "your.package.name"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
repositories {
jcenter()
mavenCentral()
maven { url 'https://maven.google.com' } // necessary for Android API 26
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-ads:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.google.android.gms:play-services-maps:15.0.0'
}
It is just a example of typical simple gradle configuration. Use as needed
回答10:
Use latest stable version of support library
Track here latest versions
https://mvnrepository.com/artifact/com.android.support
As of 28-9-2018 latest version is 28.0.0
.
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'