Beim Bauen erhalte ich folgende Fehlermeldung:
Conflict with dependency 'com.Android.support:support-annotations'. Resolved versions for app (23.1.0) and test app (23.0.1) differ.
Das sind meine Abhängigkeiten
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.Android.support:support-v4:23.1.0'
compile 'com.Android.support:appcompat-v7:23.1.0'
compile 'com.Android.support:design:23.1.0'
compile 'com.Android.support:cardview-v7:23.1.0'
compile 'com.Android.support:recyclerview-v7:23.1.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup:otto:1.3.8'
compile 'com.snappydb:snappydb-lib:0.5.2'
compile 'com.esotericsoftware.kryo:kryo:2.24.0'
compile 'com.google.dagger:dagger:2.0.1'
apt 'com.google.dagger:dagger-compiler:2.0.1'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'io.reactivex:rxjava:1.0.14'
compile 'com.google.Android.gms:play-services-location:8.1.0'
compile 'com.google.Android.gms:play-services-gcm:8.1.0'
compile 'org.Apache.commons:commons-lang3:3.4'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.Android.support.test:runner:0.4'
androidTestCompile 'com.Android.support.test:rules:0.4'
androidTestCompile 'com.Android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.Android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile 'com.Android.support.test.espresso:espresso-web:2.2.1'
debugCompile 'com.squareup.leakcanary:leakcanary-Android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-Android-no-op:1.3.1'
}
Wie kann ich das beheben?
Sie können die Anmerkungsbibliothek in Ihrem Test folgendermaßen erzwingen:
androidTestCompile 'com.Android.support:support-annotations:23.1.0'
Etwas wie das:
// Force usage of support annotations in the test app, since it is internally used by the runner module.
androidTestCompile 'com.Android.support:support-annotations:23.1.0'
androidTestCompile 'com.Android.support.test:runner:0.4.1'
androidTestCompile 'com.Android.support.test:rules:0.4.1'
androidTestCompile 'com.Android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.Android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile 'com.Android.support.test.espresso:espresso-web:2.2.1'
Eine andere Lösung besteht darin, dies in der obersten Datei zu verwenden:
configurations.all {
resolutionStrategy.force 'com.Android.support:support-annotations:23.1.0'
}
Project Rebuild hat mein Problem gelöst.
In Android Studio in der Symbolleiste .. Erstellen> Projekt neu erstellen.
Quelle: CodePath - Testen der Benutzeroberfläche mit Espresso
- Zum Schluss müssen wir die Espresso-Abhängigkeiten einholen und den Testrunner in unserer App build.gradle einstellen:
// build.gradle
...
Android {
...
defaultConfig {
...
testInstrumentationRunner "Android.support.test.runner.AndroidJUnitRunner"
}
}
dependencies {
...
androidTestCompile('com.Android.support.test.espresso:espresso-core:2.2.2') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.Android.support', module: 'support-annotations'
}
androidTestCompile('com.Android.support.test:runner:0.5') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.Android.support', module: 'support-annotations'
}
}
Ich habe das zu meiner Gradle-Datei hinzugefügt und die Warnung ist verschwunden.
Wenn Sie eine andere als widersprüchlich bezeichnete Abhängigkeit erhalten, z. B. Support-Annotationen, versuchen Sie, diese auch aus den androidTestCompile-Abhängigkeiten auszuschließen.
sie können versuchen, es zu benutzen
androidTestCompile('com.Android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.Android.support', module: 'support-annotations'
})
anstatt
androidTestCompile 'com.Android.support.test:runner:0.4.1'
androidTestCompile 'com.Android.support.test:rules:0.4.1'
androidTestCompile 'com.Android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.Android.support.test.espresso:espresso-contrib:2.2.1'
Ich habe diesen Fehler erhalten
Fehler: Ausführung fehlgeschlagen für Task ': app: preDebugAndroidTestBuild' . Konflikt mit der Abhängigkeit 'com.Android.support:support-annotations' im Projekt ': app'. Die aufgelösten Versionen für App (26.1.0) und Test-App (27.1.1) unterscheiden sich. Weitere Informationen finden Sie unter https://d.Android.com/r/tools/test-apk-dependency-conflicts.html .
Ich hatte folgende Abhängigkeiten in meiner build.gradle -Datei unter Gradle Scripts
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.Android.support:appcompat-v7:26.1.0'
implementation 'com.Android.support:support-v4:26.1.0'
implementation 'com.Android.support:support-vector-drawable:26.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'
}
Also habe ich es gelöst, indem ich die folgenden Abhängigkeiten kommentiert habe
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'
So sehen meine Abhängigkeiten so aus
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.Android.support:appcompat-v7:26.1.0'
implementation 'com.Android.support:support-v4:26.1.0'
implementation 'com.Android.support:support-vector-drawable:26.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'
}
Ich hoffe es hilft!
Ich habe heute den gleichen Fehler erhalten:
Fehler: Ausführung fehlgeschlagen für Task ': app: preDebugAndroidTestBuild'.> Konflikt mit der Abhängigkeit 'com.Android.support:support-annotations' in Projekt ': App'. Behobene Versionen für App (26.1.0) und Test-App (27.1.1) unterscheiden sich.
Was ich getan habe:
27.1.1
anstelle von 26.1.0
aktualisiert.compileSdkVersion 27
und targetSdkVersion 27
aktualisiert, die zuvor 26
warenUnd com.Android.support:support-annotations
Fehler war weg!
Für Referenz:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.Android.support:appcompat-v7:27.1.1'
implementation 'com.Android.support.constraint:constraint-layout:1.1.0'
implementation 'com.Android.support:design:27.1.1'
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'
}
In meinem Fall habe ich folgenden Code in Abhängigkeit von build.gradle auf App-Ebene hinzugefügt
androidTestCompile('com.Android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.Android.support', module: 'support-annotations'
})
Danach säubere ich das Projekt und baue es erneut auf. Mein Problem wurde behoben.
Ändern Sie Ihre build.gradle-Dateien auf Anwendungsebene:
implementation 'com.Android.support:appcompat-v7:23.1.0'
zu
implementation 'com.Android.support:appcompat-v7:23.0.1'
Versuche dies :
apply plugin: 'com.Android.application'
Android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.yourpackagename"
minSdkVersion 15
targetSdkVersion 27
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:27.1.1'
implementation 'com.Android.support.constraint:constraint-layout:1.1.3'
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'
}