2016-05-18 7 views
7

Ich versuche Android andpresso lernen .. Ich folgte einige grundlegende Tutorials und es war in Ordnung. Aber jetzt möchte ich einen Test auf Android-Navigationsschublade machen. Dafür muss ich Gradle Abhängigkeit verwenden androidTestCompile 'com.android.support.test.espresso: espresso-contrib: 2.2.2' aber es verursacht Konflikt mit anderen Abhängigkeiten. Meine gradle Datei:Android espresso-cotrib grandle build failing

apply plugin: 'com.android.application' 

android { 
compileSdkVersion 23 
buildToolsVersion "23.0.3" 

defaultConfig { 
    applicationId "my.com.myapp_android" 
    minSdkVersion 18 
    targetSdkVersion 23 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
} 
repositories { 
jcenter() 
} 
dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
testCompile 'junit:junit:4.12' 
//material design 
compile 'com.android.support:appcompat-v7:23.3.0' 
compile 'com.android.support:support-v4:23.3.0' 

//zxing 
compile 'com.journeyapps:zxing-android-embedded:[email protected]' 
compile 'com.google.zxing:core:3.2.1' 

//Testing 
// Optional -- Mockito framework 
testCompile 'org.mockito:mockito-core:1.10.19' 
androidTestCompile 'com.android.support:support-annotations:23.3.0' 
androidTestCompile 'com.android.support.test:runner:0.5' 
androidTestCompile 'com.android.support.test:rules:0.4.1' 
// Optional -- Hamcrest library 
androidTestCompile 'org.hamcrest:hamcrest-library:1.3' 
// Optional -- UI testing with Espresso 
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' 
// Optional -- UI testing with UI Automator 
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1' 




//inMarketSDK 
//compile group: 'com.inmarket', name: 'm2msdk', version: '2.29', ext: 'aar' 

} 

Fehler ist so etwas wie dieses:

Error:Conflict with dependency 'com.android.support:support-v4'. 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. 
Error:Conflict with dependency 'com.android.support:appcompat-v7'. 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. 

dies gefolgt: link für Espresso installieren

Ich habe auch versucht Anmerkung Abhängigkeit auszuschließen:

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.espresso:espresso-contrib: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' 
     } 
+0

Fehlermeldung sagt Konflikt mit 'com.android.support: support-v4' und' com.android.support: appcompat-v7'. Also versuche sie auch auszuschließen. – nenick

Antwort

27

TL; DR;

Neue Version von espresso-contrib 2.2.2 Bibliothek hat jetzt die Abhängigkeit von com.android.support:appcompat-v7:23.1.1 in Konflikt führt, wenn mit anderer Version von appcompat-v7 in unserer compile Zeitabhängigkeit unten wie:

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.4.0' 

    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' 
} 

Konflikt zu vermeiden, wenn wir appcompat-v7 Abhängigkeit von ausschließen espresso-contrib wie unten bricht es wieder aufgrund einiger Wertabhängigkeiten auf design support lib.

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){ 
    exclude module: 'support-annotations' 
    exclude module: 'support-v4' 
    exclude module: 'support-v13' 
    exclude module: 'recyclerview-v7' 
    exclude module: 'appcompat-v7' 
} 

Fehler:

Error:(69) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'.

Ursachen:

This is because the design support lib has dependency on appcompat-v7 .
So,when we exclude 'appcompat-v7' module from espresso-contrib dependencies(like above) , the design support lib downloaded as part of transitive dependency of espresso-contrib lib couldn't find the compatible version of appcompat-v7 lib(23.1.1) it is using internally in its resources files and thus gives out the above error.

Also, die Lösung obigen Problems ist 'Design-Unterstützung' lib Abhängigkeit von espresso-contrib wie unten auszuschließen:

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){ 
    exclude module: 'support-annotations' 
    exclude module: 'support-v4' 
    exclude module: 'support-v13' 
    exclude module: 'recyclerview-v7' 
    exclude module: 'design' 
} 

T Hut löst das Konfliktproblem!

längere Version (falls es jemanden interessiert):

Um die Ursachen der verschiedenen Konfliktthemen fanden heraus, dass wir konfrontiert werden, wenn mit `Espresso-contrib‘ Bibliothek i Beispielanwendung erstellt haben, um die Ursache herauszufinden, .

Step 1:Using Espresso-Contrib Lib version 2.2.1 

App Erstellt 'Espresso-contrib' lib Version 2.2 zu verwenden.1 durch folgende Zeilen in app/build.gradle Datei hinzufügen:

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 

    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1' 

}

Hinweis: In diesem Fall werde ich keine andere Unterstützung Bibliothekskomponenten wie
appcompat-v7,recyclerview-v7,etc importieren.

Die Abhängigkeitsgraphen für das obige Setup sieht unten wie:
enter image description here

Da diese espresso-contrib 2.2.1 lib Abhängigkeiten transitiv zu sehen ist auf Version 23.0.1 von
support-v4, recyclerview-v7, support-annotations, etc hat.

Da ich keine Abhängigkeiten für recyclerview-v7, support-annotations in meinem Projekt definiere, würde das obige Setup gut funktionieren.

Aber wenn wir diese als Kompilierabhängigkeiten [wie unten] in unserem Projekt definieren, erhalten wir Versionskonfliktprobleme, wie in Ihrer Frage angegeben.

compile 'com.android.support:appcompat-v7:23.3.0' 
compile 'com.android.support:support-v4:23.3.0' 

Um diese Konflikte zu vermeiden wir unter der Linie unseres Espresso-contrib lib hinzu:

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1'){ 
    exclude module: 'support-annotations' 
    exclude module: 'support-v4' 
    exclude module: 'support-v13' 
    exclude module: 'recyclerview-v7' 
} 

Dies stellt sicher, dass diese Abhängigkeiten werden nicht als Teil von espresso-contrib transitiven Abhängigkeiten heruntergeladen.
Alles läuft gut mit obigen Setup.Keine Probleme!

Step 2: Using Espresso-Contrib lib version 2.2.2 

Changed App build.gradle zu verwenden 'Espresso-contrib' lib Version 2.2.2 durch die vorherige build.gradle Datei zu ändern:

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
compile 'com.android.support:appcompat-v7:23.3.0' 
compile 'com.android.support:support-v4:23.3.0' 
testCompile 'junit:junit:4.12' 

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){ 
    exclude module: 'support-annotations' 
    exclude module: 'support-v4' 
    exclude module: 'support-v13' 
    exclude module: 'recyclerview-v7' 
    } 
} 

Aber wenn ich Projekt erstellen mit oben setup..build wird mit Fehler in Frage gestellt ..

Fehler:

Error:Conflict with dependency 'com.android.support:appcompat-v7'. 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.

Also, bei Fehlern sucht hinzugefügt i eine weitere Zeile oben build.gradle:

exclude module: 'appcompat-v7' (inside androidTestCompile block of espresso-contrib) 

Aber das löst das Problem nicht Konflikts und ich erhalte Wert Abhängigkeiten Fehler in den Kommentaren gepostet.
So überprüfen i für Abhängigkeitsdiagramm meiner App wieder: enter image description here

Wie nun zu erkennen, dass espresso-contrib 2.2.2 lib auf com.android.support:design:23.1.1 jetzt transitive Abhängigkeit hat den oben Konflikt verursacht.

Wir brauchen also unterhalb der Linie innerhalb androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2') Block hinzuzufügen:

exclude module: 'design' 

Dies löst den Konflikt Problem in lib Version 2.2.2!

+0

waw ... Perfekte Antwort. Vielen Dank. @Droidwala –

+0

@ D4Developer Ich bin froh, dass ich helfen konnte :) Sie können auf grünes Häkchen klicken, um dies als akzeptierte Antwort zu markieren, so dass es Benutzern hilft, diese Frage in Zukunft zu kommen. – Droidwala

+0

Perfekte Antwort. Vielen Dank! – Travis

0

tun Sie unter

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1'){ 
    exclude module: 'support-annotations' 
    exclude module: 'support-v4' 
    exclude module: 'recyclerview-v7' 
} 
+0

Nun, ich habe versucht auszuschließen, aber wenn ich dies schreibe Exclude-Gruppe: 'com.android.support', Modul: 'appcompat-v7'' Es bremst einige Werte Abhängigkeiten. –

+0

Ich versuchte dieses 'transitive = false' und es funktionierte, obwohl. Aber nicht sicher, ob das eine gute Lösung ist –