Conflitto con la dipendenza "com.android.support:support-annotations". Le versioni risolte per l'app (23.1.0) e l'app di prova (23.0.1) differiscono


119

Durante la compilazione ottengo il seguente errore:

Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.1.0) and test app (23.0.1) differ.

Queste sono le mie graduali dipendenze

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'
}

Come posso risolvere questo problema?


Posso dirti che la dipendenza 23.1.0 proviene da appcompat lib, perché include le annotazioni lib. Il 23.0.1 non lo so
— Tim

Non funziona nemmeno se cambio appcompat di nuovo su 23.0.1
— barq

Ho appena sostituito 23.1.0 con 23.0.1, ovunque in dipendenza, ha funzionato per me.
— Shahzad Afridi

Aggiungi la dipendenza dell'annotazione relativa al tuo errore di versione. readyandroid.wordpress.com/…
— Pronto Android

O questo potrebbe aiutarti readyandroid.wordpress.com/…
— Pronto Android

Risposte:


208

Puoi forzare la libreria di annotazioni nel tuo test utilizzando:

androidTestCompile 'com.android.support:support-annotations:23.1.0'

Qualcosa come questo:

  // 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'

Un'altra soluzione è usarlo nel file di primo livello:

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
}

8
Questa riga era la soluzione: androidTestCompile 'com.android.support:support-annotations:23.1.0'
— barq

4
L'uso dell'impostazione configurations.all ha funzionato per me, ma non nel file a livello di progetto, che è quello che ho interpretato inizialmente come "file di primo livello" dalla risposta sopra. Era nel file build.gradle a livello di modulo
— OYRM

Questo conflitto è originariamente causato da Espresso?
— IgorGanapolsky

resolutionStrategy.force 'com.android.support:support-annotations:23.4.0' non aiuta per me .. il problema è EspressoContribution per DatePicker, DrawerActions, RecyclerView, ecc. ('com.android.support.test.espresso : espresso-contrib: 2.2.2 ') {exclude module:' support-annotations 'exclude module:' support-v4 '}
— Ewoks

3
Solo un punto importante, per chiarire che dobbiamo aggiungere configurations.all {resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'} all'interno build.gradledel modulo (app) per risolvere il problema.
— Programmazione AAD il

69

Project Rebuild ha risolto il mio problema.

In Android Studio nella barra degli strumenti .. Crea> Ricostruisci progetto.


25

Fonte: CodePath - Test dell'interfaccia utente con Espresso

  1. Infine, dobbiamo inserire le dipendenze Espresso e impostare il test runner nella nostra app build.gradle:
// 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'
    }
}

L'ho aggiunto al mio file gradle e l'avviso è scomparso.

Inoltre, se ottieni qualsiasi altra dipendenza elencata come in conflitto, come le annotazioni di supporto, prova a escluderla anche dalle dipendenze androidTestCompile.


1
escluso il singolo androidtestcompile funziona per me
— Nantha kumar

12

puoi provare a usare

  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

invece di

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'

6

Ho ricevuto questo errore

Errore: esecuzione non riuscita per l'attività ": app: preDebugAndroidTestBuild". Conflitto con la dipendenza "com.android.support:support-annotations" nel progetto ": app". Le versioni risolte per l'app (26.1.0) e l'app di prova (27.1.1) differiscono. Vedi https://d.android.com/r/tools/test-apk-dependency-conflicts.html per i dettagli.

Avevo le seguenti dipendenze nel mio file build.gradle in 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'
}

Quindi, l'ho risolto commentando le seguenti dipendenze

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'

Quindi le mie dipendenze assomigliano a questo

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'
}

Spero che sia d'aiuto!


1
Quindi hai rimosso le librerie di test? Questo non è molto utile se hai bisogno di quelle librerie.
— Pantaloni

4

Oggi ho ricevuto lo stesso errore:

Errore: esecuzione non riuscita per l'attività ": app: preDebugAndroidTestBuild".> Conflitto con la dipendenza "com.android.support:support-annotations" nel progetto ": app". Le versioni risolte per l'app (26.1.0) e l'app di prova (27.1.1) differiscono.

Cosa ho fatto:

  • Ho semplicemente aggiornato tutte le mie dipendenze a 27.1.1invece di26.1.0
  • Inoltre, ho aggiornato il mio compileSdkVersion 27e targetSdkVersion 27che erano 26precedenti

E l' com.android.support:support-annotationserrore era sparito!

Per rif:

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'
}

1

Nel mio caso, ho aggiunto il codice di seguito nelle dipendenze del livello di app build.gradle

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

Dopodiché, pulisco il progetto e ricostruisco.Il mio problema è stato risolto.


0

Cambia il tuo file build.gradle a livello di applicazione:

implementation 'com.android.support:appcompat-v7:23.1.0'

per

 implementation 'com.android.support:appcompat-v7:23.0.1'

0

Prova questo :

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'
}
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.