android - 生成APK问题 : java. lang.RuntimeException : com. android.builder.dexing.DexArchiveMergerException: Unable to merge dex

标签 android gradle android-gradle-plugin build.gradle

我在 Windows 10 上有 Android Studio,每当我尝试调试我的应用程序时都会出现此错误:

enter image description here

这是我的项目级别 build.gradle

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3"
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://jitpack.io' }
        maven {
            url 'https://maven.google.com'
        }
        google()
    }
}

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

这是模块级别 build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '26.0.3'
    defaultConfig {
        applicationId "com.dzboot.salha.client"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.home_fragment.runner.AndroidJUnitRunner"
    }
    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath = true
            }
        }
    }
}

dependencies {
    implementation('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.6.2') {
        transitive = true
    }

    def firebaseVersion = '11.8.0'
    def playservicesVersion = '11.8.0'
    def androidSupportVersion = '27.1.0'

    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.6.2'
    implementation "com.google.firebase:firebase-auth:$firebaseVersion"
    implementation "com.google.firebase:firebase-messaging:$firebaseVersion"
    implementation 'com.github.TheBrownArrow:PermissionManager:1.0.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'gun0912.ted:tedbottompicker:1.0.12'
    implementation 'com.akexorcist:googledirectionlibrary:1.0.5'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation "com.google.android.gms:play-services-maps:$playservicesVersion"
    implementation "com.google.android.gms:play-services-location:$playservicesVersion"
    implementation "com.google.android.gms:play-services-places:$playservicesVersion"
    implementation "com.google.android.gms:play-services-base:$playservicesVersion"
    implementation "com.google.firebase:firebase-database:$firebaseVersion"
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.android.support:multidex:1.0.3'

    implementation "com.android.support:cardview-v7:$androidSupportVersion"
    implementation "com.android.support:appcompat-v7:$androidSupportVersion"
    implementation "com.android.support:design:$androidSupportVersion"
}

apply plugin: 'com.google.gms.google-services'

我尝试清理项目,使缓存无效并重新启动,还尝试运行:gradlew -q dependancies要查看任何冲突,这就是我得到的:

Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring project ':app'.

    Failed to notify project evaluation listener. Could not initialize class com.android.sdklib.repository.AndroidSdkHandler

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。
  • https://help.gradle.org 获得更多帮助


  • 1 秒内构建失败

    还有我的 gradle-wrapper.propeties:
    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
    

    编辑 引用下面关于多个 Java 版本的评论。我确实有两个 Java 版本,我保留了 Java 8u161 并卸载了另一个,我在我的 中更改了 Java 的位置项目结构设置 ,但我仍然有同样的问题。

    我真的很迷茫,请帮助我!

最佳答案

感谢@shadowsheep,我解决了这个问题。我在应用程序级别添加了这个 build.gradle

dependencies {
    /.../
    implementation "android.arch.lifecycle:extensions:1.1.0"
}

在模拟器中运行应用程序运行良好,但在尝试生成 apk 时出现了很多警告和错误。

然后我不得不从同一个文件中删除它以使其工作:
buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

如果有人知道如何使它与 ProGuard 一起工作,请挺身而出 :)

关于android - 生成APK问题 : java. lang.RuntimeException : com. android.builder.dexing.DexArchiveMergerException: Unable to merge dex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49214170/

相关文章:

java - 安卓|获取文件 (.zip) 并保存

gradle - 如何让Gradle任务设置shell设置环境变量?

java - 在使用我的Gradle插件的Gradle项目上添加第二个源文件夹

android - 错误 : error while writing **** File name too long

Android Studio - 找不到 org.jetbrains.kotlin :kotlin-stdlib:1. 1.3-2

android - Unity创建移动图案背景

android - 如何在 Android 中将 JSON ARRAY 数据发布到服务器

android - 使用循环进度条作为 alertdialog 或 progressdialog

android - 如何在 android 中修复错误 "Could not find com.android.tools.build:gradle:3.4.1"?

react-native - react native : Error: Duplicate resources - Android