Bağımlılık "com.android.support:support-annotations" ile çakışma. Uygulama (23.1.0) ve test uygulaması (23.0.1) için çözümlenen sürümler farklı


119

İnşa ederken aşağıdaki hatayı alıyorum:

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

Bunlar benim kademeli bağımlılıklarım

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

Bunu nasıl düzeltebilirim?


23.1.0 bağımlılığının appcompat lib'den geldiğini söyleyebilirim, çünkü bu ek açıklamalar lib'yi içerir. Bilmiyorum 23.0.1
— Tim

Appcompat'ı 23.0.1'e geri döndürürsem de çalışmıyor
— barq

23.1.0'ı 23.0.1 ile değiştirdim, her yerde bağımlılık benim için çalıştı.
— Shahzad Afridi

Sürüm hatanızla ilgili ek açıklama bağımlılığı ekleyin. readyandroid.wordpress.com/…
— Hazır Android

Yanıtlar:


208

Ek açıklama kitaplığını testinizde aşağıdakileri kullanarak zorlayabilirsiniz:

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

Bunun gibi bir şey:

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

Başka bir çözüm de bunu en üst düzey dosyada kullanmaktır:

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

8
Bu satır çözümdü: androidTestCompile 'com.android.support:support-annotations:23.1.0'
— barq

4
Konfigürasyonlar.all ayarının kullanımı benim için işe yaradı, ancak proje seviyesi dosyasında işe yaramadı. Bu, yukarıdaki yanıttan başlangıçta "üst seviye dosya" olarak yorumladığım şeydi. Modül seviyesi build.gradle dosyasındaydı
— OYRM

Bu uyuşmazlığın nedeni aslında Espresso mu?
— IgorGanapolsky

ResolutionStrategy.force 'com.android.support:support-annotations:23.4.0' bana yardımcı olmuyor .. sorun, DatePicker, DrawerActions, RecyclerView, vb. için EspressoContribution. ('com.android.support.test.espresso : espresso-Contributor: 2.2.2 ') {exclude module:' support-annotations 'modülü hariç tut:' support-v4 '}
— Ewoks,

3
Sadece bir önemli nokta, bu Biz configurations.all {resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'} içini eklemek gerektiğini temizlemek yapmak için build.gradlebir modül (app) sorunu gidermek için.
— AADProgramming

69

Project Rebuild sorunumu çözdü.

Araç çubuğundaki Android stüdyosunda .. İnşa Et> Projeyi Yeniden Oluştur.


25

Kaynak: CodePath - Espresso ile Kullanıcı Arayüzü Testi

  1. Son olarak, Espresso bağımlılıklarını devreye almamız ve test çalıştırıcısını uygulama build.gradle'da ayarlamamız gerekiyor:
// 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'
    }
}

Bunu gradle dosyama ekledim ve uyarı kayboldu.

Ayrıca, destek ek açıklamaları gibi çakışan olarak listelenen başka bir bağımlılık alırsanız, bunu androidTestCompile bağımlılıklarından da çıkarmayı deneyin.


1
bireysel androidtest derlemesi hariç benim için çalışıyor
— Nantha kumar

12

kullanmayı deneyebilirsin

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

onun yerine

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

Bu hatayı alıyordum

Hata: ': app: preDebugAndroidTestBuild' görevi için yürütme başarısız oldu. ': App' projesinde bağımlılık 'com.android.support:support-annotations' ile çakışma Uygulama (26.1.0) ve test uygulaması (27.1.1) için çözümlenen sürümler farklıdır. Ayrıntılar için https://d.android.com/r/tools/test-apk-dependency-conflicts.html adresine bakın.

Gradle Scripts altındaki build.gradle dosyamda aşağıdaki bağımlılıklar yaşıyordum

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

Bu yüzden aşağıdaki bağımlılıkları yorumlayarak çözdüm

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'

Yani bağımlılıklarım böyle görünüyor

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

Umarım yardımcı olur!


1
Yani test kitaplıklarını kaldırdınız mı? Bu kitaplıklara ihtiyacınız varsa bu pek yardımcı olmaz.
— Pantolon

4

Bugün aynı hatayı alıyordum:

Hata: ': app: preDebugAndroidTestBuild' görevi için yürütme başarısız oldu.> ': App' projesinde 'com.android.support:support-annotations' bağımlılığıyla çakışma. Uygulama (26.1.0) ve test uygulaması (27.1.1) için çözümlenen sürümler farklıdır.

Ben ne yaptım:

  • Ben sadece için bütün bağımlılıkları güncellenen 27.1.1yerine26.1.0
  • Ayrıca, benim compileSdkVersion 27ve targetSdkVersion 27daha 26önce olanları güncelledi

Ve com.android.support:support-annotationshata gitti!

Referans için:

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

Benim durumumda, uygulama düzeyinde build.gradle bağımlılıklarına aşağıdaki kodu ekledim

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

Ondan sonra projeyi temizleyip yeniden inşa ediyorum, sorunum çözüldü.


0

Uygulama düzeyi build.gradle dosyanızı değiştirin:

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

için

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

0

Bunu dene :

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'
}
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.