web-dev-qa-db-ja.com

依存関係 'com.Android.support:support-annotations'と競合しています。アプリ(23.1.0)とテストアプリ(23.0.1)の解決されたバージョンは異なります

構築時に私は次のエラーが出ます:

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

これらは私のgradle依存関係です

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

どうすればこれを修正できますか?

118
barq

次のようにして、テストに注釈ライブラリを強制することができます。

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

このようなもの:

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

別の解決策はこれをトップレベルファイルで使用することです:

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

プロジェクト再構築は私の問題を解決しました。

ツールバーのAndroid Studioで、[ビルド]> [プロジェクトの再ビルド]をクリックします。

68
Sushanth Kille

出典: CodePath - EspressoによるUIテスト

  1. 最後に、Espressoの依存関係を取り込み、アプリの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'
    }
}

私はそれを自分のgradleファイルに追加しましたが、警告は消えました。

また、support-annotationsなど、他の依存関係が競合としてリストされている場合は、androidTestCompile依存関係からも除外してみてください。

25
rexxar

あなたが使用しようとすることができます

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

の代わりに

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'
12
jingsong yang

このエラーが出ました

エラー:タスク ':app:preDebugAndroidTestBuild'の実行に失敗しました。プロジェクト ':app'の依存関係 'com.Android.support:support-annotations'と競合しています。アプリ(26.1.0)とテストアプリ(27.1.1)の解決バージョンは異なります。詳細については、 https://d.Android.com/r/tools/test-apk-dependency-conflicts.html を参照してください。

Gradle Scriptsの下のbuild.gradleファイルに次のような依存関係がありました。

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

それで、私は以下の依存関係をコメントすることによってそれを解決しました

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'

だから私の依存関係はこのようになります

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

それが役に立てば幸い!

4
Shahbaz Ali

今日も同じエラーになりました:

エラー:タスク ':app:preDebugAndroidTestBuild'の実行に失敗しました>プロジェクト ':app'の依存関係 'com.Android.support:support-annotations'と競合していますアプリ(26.1.0)とテストアプリ(27.1.1)の解決バージョンは異なります。

私がしたこと:

  • 27.1.1ではなく26.1.0にすべての依存関係を更新しました
  • また、以前のcompileSdkVersion 27であった私のtargetSdkVersion 2726を更新しました

そしてcom.Android.support:support-annotationsエラーがなくなりました!

Ref:

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'
}
4
Rohit Sharma

私の場合は、アプリレベルのbuild.gradleの依存関係に、以下のコードを追加しました。

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

その後、私はプロジェクトをきれいにして再構築します。私の問題は解決しました。

1
Mohammed Nishar

アプリケーションレベルのbuild.gradleファイルを変更します。

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

 implementation 'com.Android.support:appcompat-v7:23.0.1'
0
chetu

これを試して :

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