【问题标题】:Generating APK problems: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex生成APK问题:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
【发布时间】:2018-08-19 05:31:15
【问题描述】:

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

这是我的项目级别 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 看到任何冲突,这是我得到的:

项目 ':app' 中的配置 'compile' 已弃用。采用 改为“实施”。

FAILURE:构建失败并出现异常。

  • 出了什么问题:配置项目 ':app' 时出现问题。

    未能通知项目评估侦听器。 无法初始化类 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 的位置,但我仍然遇到同样的问题。

我真的迷路了,请帮帮我!

【问题讨论】:

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


【解决方案1】:

感谢@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 一起工作,请站出来 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多