错误:com.android.builder.dexing.DexArchiveBuilderException:无法处理guava-21.0.jar Android 3.1 Dev Channel

Ata*_*tak 65 android guava android-gradle-plugin android-studio-3.0

更新我的依赖版本后AndroidStudio3.1,我开始收到以下错误:

    Information:Gradle tasks [:app:assembleDebug]
Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\Blabla\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar
Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
Error:com.android.tools.r8.ApiLevelException: Default interface methods are only supported starting with Android N (--min-api 24): java.util.Collection com.google.common.collect.BiMap.values()
Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\Blabla\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar
Information:BUILD FAILED in 6s
Information:4 errors
Information:0 warnings
Information:See complete output in console
Run Code Online (Sandbox Code Playgroud)

我已经清理并重建了项目.检查了我的"multiDexEnabled true"''编译'com.android.support:multidex:1.0.2'已添加.

我还可以做些什么?

编辑:添加build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.blabla"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:27.0.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support:design:27.0.0'
    compile 'com.android.support:cardview-v7:27.0.0'
    compile 'com.jakewharton:butterknife:8.7.0'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.google.guava:guava:21.0'
    compile 'com.microsoft.azure:azure-mobile-android:3.2.0@aar'
    compile 'com.microsoft.azure:notification-hubs-android-sdk:0.4@aar'
    compile 'com.microsoft.azure:azure-notifications-handler:1.0.1@aar'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.google.firebase:firebase-core:11.4.2'
    compile 'com.google.firebase:firebase-crash:11.4.2'
    compile 'com.google.firebase:firebase-auth:11.4.2'
    compile 'com.google.firebase:firebase-database:11.4.2'
    compile 'com.google.firebase:firebase-storage:11.4.2'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
    compile 'com.google.android.gms:play-services-maps:11.4.2'
    compile 'com.google.android.gms:play-services-location:11.4.2'
    compile 'com.google.maps.android:android-maps-utils:0.5+'
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

小智 84

我在react-native项目中遇到了同样的问题,

以下线路为我工作,

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
} 
Run Code Online (Sandbox Code Playgroud)

  • 这应该是正确的答案.该错误与您尝试使用的java的更高版本的java上的依赖项有关.因此,使用最新版本编译项目,而不是相反,并为项目添加混乱配置. (8认同)
  • 弄清楚了,它起作用了,谢谢。您可以在此处进行更改:build.gradle(模块:app),然后在android属性中进行更改。 (2认同)

Oli*_*ire 41

更新您的Guava版本

Guava 21仅限Java 8.

将您的gradle更新27.0.1-android为与Android兼容的Guava版本:

Gradle 4.6+:

dependencies {
  implementation 'com.google.guava:guava:27.0.1-android'
}
Run Code Online (Sandbox Code Playgroud)

以前的Gradle版本:

dependencies {
  compile 'com.google.guava:guava:27.0.1-android'
}
Run Code Online (Sandbox Code Playgroud)

  • 而已。但是我还必须添加以下内容,以解决添加您的依赖关系后的另一个错误:`android {configuration.all {resolutionStrategy.force'com.google.code.findbugs:jsr305:1.3.9'}} (2认同)

小智 9

我遇到了同样的问题,并解决了清理项目并重建它的问题。

在Android Studio中,转到Build-> Clean Project,然后执行Build-> Rebuild Project

希望能帮助到你