2016-05-28 15 views
3

私は自分のプロジェクトにエスプレッソ投稿ライブラリを追加しようとしています。ここに私のbuild.gradleファイルには、次のとおりです。Androidのコンフリクトと依存関係のコンパイル

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    defaultConfig { 
     applicationId "example.com.littlebox_hari" 
     minSdkVersion 19 
     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' 
     } 
    } 
    /*configurations.all { 
     resolutionStrategy { 
      force 'com.android.support:appcompat-v7:23.4.0' 
     } 
    }*/ 
} 


dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.squareup.retrofit2:retrofit:2.0.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.0.0' 
    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.uiautomator:uiautomator-v18:2.1.2' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' 
    androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2' 
    compile 'com.android.support:support-annotations:23.4.0' 
    testCompile 'com.android.support:support-annotations:23.4.0' 
    androidTestCompile 'com.android.support:support-annotations:23.4.0' 
} 

私はこのエラーを取得する:

Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details. 

私は私のbuild.gradleファイル内の行のコメントを解除した場合、私が手:

Error:(72) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'. 
Error:(75) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Caption'. 
Error:(79) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Caption'. 
Error:(76) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Caption'. 
Error:(82) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Caption'. 
Error:(89) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Button'. 
D:\Littlebox-Hari\app\build\intermediates\exploded-aar\com.android.support\design\23.1.1\res\values\values.xml 
Error:(97, 5) No resource found that matches the given name: attr 'textAllCaps'. 
Error:(102, 5) No resource found that matches the given name: attr 'elevation'. 
Error:(113, 5) No resource found that matches the given name: attr 'backgroundTint'. 
Error:(113, 5) No resource found that matches the given name: attr 'elevation'. 
Error:(122, 5) No resource found that matches the given name: attr 'elevation'. 
Error:(131, 5) No resource found that matches the given name: attr 'elevation'. 

編集:build.gradleファイルに次の行を追加しました:

testCompile 'com.android.support:appcompat-v7:23.4.0' 
androidTestCompile 'com.android.support:appcompat-v7:23.4.0' 

私はまだ同じエラーが発生します。

+0

あなたはエラーが提供されたURLを読みましたか? –

+0

[Gradle:アプリとテストアプリの解決版が異なる]の可能な複製(http://stackoverflow.com/questions/34650509/gradle-resolved-versions-for-app-and-test-app-differ) –

+0

編集済み - 私は同じエラーを受けた – rhari

答えて

16

今日もこの問題に直面しました。

まず、最新バージョン(0.5および2.2.2)に依存関係を更新します。

は参照してください:最新バージョンはまだ(23.4.0)今のところ、サポートライブラリの最新バージョンを使用していないのでhttps://google.github.io/android-testing-support-library/downloads/

// Android JUnit Runner 
androidTestCompile 'com.android.support.test:runner:0.5' 

// JUnit4 Rules 
androidTestCompile 'com.android.support.test:rules:0.5' 

// Espresso core 
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 

// Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource 
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' 

// Espresso-web for WebView support 
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2' 

// Espresso-idling-resource for synchronization with background jobs 
androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2' 

その後、あなたは、同じエラーに直面します。

:これは私のために働いた https://code.google.com/p/android/issues/detail?id=211490

dependencies { 
    ext { 
     supportLibVersion = '23.4.0' 
     espressoVersion = '2.2.2' 
    } 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    androidTestCompile 'com.android.support.test:runner:0.5' 
    androidTestCompile 'com.android.support.test:rules:0.5' 
    androidTestCompile "com.android.support.test.espresso:espresso-core:$espressoVersion" 
    androidTestCompile ("com.android.support.test.espresso:espresso-contrib:$espressoVersion") { 
     exclude module: 'recyclerview-v7' 
     exclude module: 'design' 
    } 
    androidTestCompile "com.android.support.test.espresso:espresso-web:$espressoVersion" 
    androidTestCompile "com.android.support.test.espresso:espresso-idling-resource:$espressoVersion" 
    androidTestCompile "com.android.support:support-annotations:$supportLibVersion" 
    compile "com.android.support:appcompat-v7:$supportLibVersion" 
    compile "com.android.support:design:$supportLibVersion" 
    compile "com.android.support:appcompat-v7:$supportLibVersion" 
    compile "com.android.support:recyclerview-v7:$supportLibVersion" 
} 

EDIT:すでにバグトラッカー上の未解決の問題があります、これは正しい方法であるように このコードパスguideによるが、それはそうです

ext { 
    supportLibVersion = '24.1.1' 
    espressoVersion = '2.2.2' 
    junitVersion = '4.12' 
    mockitoVersion = '1.10.19' 
    hamcrestVersion = '1.3' 
    powerMockitoVersion = '1.6.5' 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile "com.android.support:appcompat-v7:$supportLibVersion" 
    compile "com.android.support:design:$supportLibVersion" 
    compile "com.android.support:recyclerview-v7:$supportLibVersion" 

    // Testing dependencies 
    testCompile "junit:junit:$junitVersion" 
    testCompile "org.mockito:mockito-all:$mockitoVersion" 
    testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion" 
    testCompile "org.powermock:powermock-module-junit4:$powerMockitoVersion" 
    testCompile "org.powermock:powermock-api-mockito:$powerMockitoVersion" 
    androidTestCompile 'com.android.support.test:runner:0.5' 
    androidTestCompile 'com.android.support.test:rules:0.5' 
    androidTestCompile "com.android.support.test.espresso:espresso-core:$espressoVersion" 
    androidTestCompile "com.android.support.test.espresso:espresso-contrib:$espressoVersion" 
    androidTestCompile "com.android.support.test.espresso:espresso-web:$espressoVersion" 
    androidTestCompile "com.android.support.test.espresso:espresso-idling-resource:$espressoVersion" 
} 

configurations.all { 
    resolutionStrategy.force "com.android.support:support-annotations:$supportLibVersion" 
} 

configurations.compile.dependencies.each { compileDependency -> 
    println "Excluding compile dependency: ${compileDependency.getName()}" 
    configurations.androidTestCompile.dependencies.each { androidTestCompileDependency -> 
    configurations.androidTestCompile.exclude module: "${compileDependency.getName()}" 
} 
+0

うん、これは私のために働いた。どうもありがとうございました ! – rhari

+0

私はこの1行をespresso-contrib excludesに追加しなければなりません:excludeモジュール: 'support-v4' –

0

これらの2つの設定は、他にもたくさんのbuild.gradleファイルをハッキングして私の仕事をしてくれました。率直に言ってGradleとそれがシステムを吸う(完全にCMake/Rake/Scons/Makeより劣っている)のため、まだ変更されていないGoogleの独自の推奨されたgradleファイルからのgradleファイルとマージされたcountles swebsitesのハッキングされたgradleファイルとのマージ)。

/*メインbuid.gradle */

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

plugins { 
    id 'java' 
    id "com.github.tkruse.groovysh" version "1.0.8" // optional 
} 


allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

// Define versions in a single place 
ext { 
    // Sdk and tools 
    minSdkVersion = 10 
    targetSdkVersion = 22 
    compileSdkVersion = 23 
    buildToolsVersion = '23.0.3' 

    // App dependencies 
    supportLibraryVersion = '23.4.0' 
    guavaVersion = '18.0' 
    glideVersion = '3.6.1' 
    junitVersion = '4.12' 
    mockitoVersion = '1.10.19' 
    powerMockito = '1.6.2' 
    hamcrestVersion = '1.3' 
    runnerVersion = '0.5' 
    rulesVersion = '0.5' 
    espressoVersion = '2.2.2' 
} 

アプリ/ build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion rootProject.ext.compileSdkVersion 
    buildToolsVersion rootProject.ext.buildToolsVersion 

    defaultConfig { 
     applicationId "com.example.android.testing.notes" 
     minSdkVersion rootProject.ext.minSdkVersion 
     targetSdkVersion rootProject.ext.targetSdkVersion 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' 
    } 
    buildTypes { 
     debug { 
      // Run code coverage reports by default on debug builds. 
      testCoverageEnabled = true 
     } 
    } 

    // If you need to add more flavors, consider using flavor dimensions. 
    productFlavors { 
     mock { 
      applicationIdSuffix = ".mock" 
     } 
     prod { 

     } 
    } 

    // Remove mockRelease as it's not needed. 
    android.variantFilter { variant -> 
     if(variant.buildType.name.equals('release') 
       && variant.getFlavors().get(0).name.equals('mock')) { 
      variant.setIgnore(true); 
     } 
    } 

    // Always show the result of every unit test, even if it passes. 
    testOptions.unitTests.all { 
     testLogging { 
      events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' 
     } 
    } 

} 

/* 
Dependency versions are defined in the top level build.gradle file. This helps keeping track of 
all versions in a single place. This improves readability and helps managing project complexity. 
*/ 
dependencies { 
    // App's dependencies, including test 
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion" 
    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion" 
    compile "com.android.support:design:$rootProject.supportLibraryVersion" 
    compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion" 
    compile "com.android.support:support-v4:$rootProject.supportLibraryVersion" 
    compile "com.google.guava:guava:$rootProject.guavaVersion" 
    compile "com.github.bumptech.glide:glide:$rootProject.glideVersion" 
    compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.ext.espressoVersion" 

    // Dependencies for local unit tests 
    testCompile "junit:junit:$rootProject.ext.junitVersion" 
    testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion" 
    testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion" 
    testCompile "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito" 
    testCompile "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito" 

    // Android Testing Support Library's runner and rules 
    androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion" 
    androidTestCompile "com.android.support.test:rules:$rootProject.ext.rulesVersion" 

    // Espresso UI Testing dependencies. 
    androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion" 
    androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion" 
    androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion" 
} 

/* 
Resolves dependency versions across test and production APKs, specifically, transitive 
dependencies. This is required since Espresso internally has a dependency on support-annotations. 
*/ 
configurations.all { 
    resolutionStrategy.force "com.android.support:support-annotations:$rootProject.supportLibraryVersion" 
} 

/* 
All direct/transitive dependencies shared between your test and production APKs need to be 
excluded from the test APK! This is necessary because both APKs will contain the same classes. Not 
excluding these dependencies from your test configuration will result in an dex pre-verifier error 
at runtime. More info in this tools bug: (https://code.google.com/p/android/issues/detail?id=192497) 
*/ 
configurations.compile.dependencies.each { compileDependency -> 
    println "Excluding compile dependency: ${compileDependency.getName()}" 
    configurations.androidTestCompile.dependencies.each { androidTestCompileDependency -> 
     configurations.androidTestCompile.exclude module: "${compileDependency.getName()}" 
    } 
} 
関連する問題