Gradle 错误 - 任务执行失败 app:prepareDebugAndroidTestDependencies

Gradle error - Execution failed for task app:prepareDebugAndroidTestDependencies

我正在尝试将 MapBox 库添加到项目中。但是,当我尝试 运行 应用程序时,它一直失败并出现 1 个错误。

build.gradle

buildscript {
  repositories {
      maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
      classpath 'io.fabric.tools:gradle:1.+'
  }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
apply from: '../config/quality/quality.gradle'


android {
  compileSdkVersion 25
  buildToolsVersion "24.0.3"
  defaultConfig {
      applicationId "com.hopegasolane"
      minSdkVersion 16
      targetSdkVersion 25
      versionCode 1
      versionName "1.0"
}

signingConfigs {
    release {
        storeFile file('keystore/release.keystore')
        keyAlias 'alias'
        storePassword "$System.env.APP_KEY"
        keyPassword "$System.env.APP_KEY"
    }

    debug {
        storeFile file('keystore/debug.keystore')
        keyAlias 'androiddebugkey'
        storePassword 'android'
        keyPassword 'android'
    }
}

buildTypes {
    release {
        signingConfig signingConfigs.release

        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    debug {
        versionNameSuffix " Debug"
        debuggable true
    }
}

lintOptions {
    warning 'InvalidPackage'
  }
}

repositories {
jcenter()
maven {
    url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
  final PLAY_SERVICES_VERSION = '9.8.0'
  final SUPPORT_LIBRARY_VERSION = '25.0.0'
  final RETROFIT_VERSION = '2.1.0'
  final DAGGER_VERSION = '2.5'
  final DEXMAKER_VERSION = '1.4'
  final HAMCREST_VERSION = '1.3'
  final ESPRESSO_VERSION = '2.2.2'
  final RUNNER_VERSION = '0.4'
  final BUTTERKNIFE_VERSION = '8.4.0'
  final TRANSITIONS_EVERYWHERE = '1.6.9'

  def daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
  def jUnit = "junit:junit:4.12"
  def mockito = "org.mockito:mockito-core:1.10.19"


  compile "com.google.android.gms:play-services-gcm:$PLAY_SERVICES_VERSION"
  compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
  compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
  compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
  compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
  compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"

  compile "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
  compile "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
  compile "com.squareup.retrofit2:adapter-rxjava:$RETROFIT_VERSION"

  compile "com.andkulikov:transitionseverywhere:$TRANSITIONS_EVERYWHERE"


  compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
  apt "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"


  compile "com.google.dagger:dagger:$DAGGER_VERSION"
  apt daggerCompiler
  testApt daggerCompiler


  androidTestCompile jUnit
  androidTestCompile mockito
  androidTestCompile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
  androidTestCompile("com.android.support.test.espresso:espresso-contrib:$ESPRESSO_VERSION") {
      exclude group: 'com.android.support', module: 'appcompat'
      exclude group: 'com.android.support', module: 'support-v4'
      exclude group: 'com.android.support', module: 'recyclerview-v7'
  }
  androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION"
  androidTestCompile "com.android.support.test:runner:$RUNNER_VERSION"
  androidTestCompile "com.android.support.test:rules:$RUNNER_VERSION"
  androidTestCompile "com.crittercism.dexmaker:dexmaker:$DEXMAKER_VERSION"
  androidTestCompile "com.crittercism.dexmaker:dexmaker-dx:$DEXMAKER_VERSION"
  androidTestCompile "com.crittercism.dexmaker:dexmaker-mockito:$DEXMAKER_VERSION"


  testCompile jUnit
  testCompile mockito
  testCompile "org.hamcrest:hamcrest-core:$HAMCREST_VERSION"
  testCompile "org.hamcrest:hamcrest-library:$HAMCREST_VERSION"
  testCompile "org.hamcrest:hamcrest-integration:$HAMCREST_VERSION"
  compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
  compile 'com.github.bumptech.glide:glide:3.7.0'
  compile 'io.reactivex:rxandroid:1.2.1'
  compile 'io.reactivex:rxjava:1.1.6'
  compile 'com.facebook.stetho:stetho:1.4.1'
  compile 'com.uphyca:stetho_realm:2.0.0'
  compile 'com.jakewharton.timber:timber:4.1.2'
  testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
  testCompile 'org.robolectric:robolectric:3.1'
  annotationProcessor 'com.squareup:javapoet:1.7.0'
  debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
  provided 'org.glassfish:javax.annotation:10.0-b28'
  releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
  compile('com.mapbox.mapboxsdk:mapbox-android-sdk:4.1.1@aar') {
      transitive = true;
  }
  compile('io.fabric.sdk.android:fabric:1.3.10@aar') {
      transitive = true;
  }
}

这是错误信息:

Warning:Conflict with dependency 'com.google.guava:guava'. Resolved versions for app (18.0) and test app (19.0-rc2) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

Error:Execution failed for task ':app:prepareDebugAndroidTestDependencies'. Dependency Error. See console for details.

编辑

compile('com.mapbox.mapboxsdk:mapbox-android-sdk:4.1.1@aar') {
    transitive = true;
    compile 'com.google.guava:guava:19.0-rc2'
    exclude group: 'com.google.guava', module: 'guava'
}

据我所知,guava 不是 Mapbox Android SDK 的依赖项...查看您的编辑,Mapbox Android 依赖项应该仅为:

compile('com.mapbox.mapboxsdk:mapbox-android-sdk:4.1.1@aar') {
    transitive = true;
}

就像你原来的那样post。如果问题仍然存在,post查看整个错误消息会有所帮助。