无法合并 Dex - Android Studio 3.0 [英] Unable to Merge Dex - Android Studio 3.0

查看:26
本文介绍了无法合并 Dex - Android Studio 3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在稳定版中将我的 Android Studio 更新到 3.0 并运行该项目时,我开始收到以下错误.

When I updated my Android Studio to 3.0 in the stable channel and ran the project, I started getting the below error.

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

我尝试清理和重建项目,但没有奏效.任何帮助将不胜感激.

I tried cleaning and rebuilding the project, but it didn't work. Any help will be appreciated.

项目级 build.gradle

Project level build.gradle

buildscript {
repositories {
    jcenter()
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath 'com.google.gms:google-services:3.1.0'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
} 
allprojects {
repositories {
    jcenter()
    google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

应用级 build.gradle

App level build.gradle

apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
    applicationId "com.med.app"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    resConfigs "auto"
    multiDexEnabled true

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}
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.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'

//appcompat libraries
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'


//butterknife
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

//picasso
compile 'com.squareup.picasso:picasso:2.5.2'

//material edittext
compile 'com.rengwuxian.materialedittext:library:2.1.4'

// Retrofit & OkHttp & and OkHttpInterceptor & gson
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'

// FirebaseUI for Firebase Auth
compile 'com.firebaseui:firebase-ui-auth:3.1.0'
}
apply plugin: 'com.google.gms.google-services'

我已经尝试了所有给出的答案,但我无法解决这个错误.请帮忙.

I have tried all the answers given but I am unable to solve this error. Please help.

推荐答案

将显式依赖添加到 play-services-auth 以及您的 firebase-ui-auth 依赖:

Add an explicit dependency to play-services-auth along with your firebase-ui-auth dependency:

// FirebaseUI for Firebase Auth
    compile 'com.firebaseui:firebase-ui-auth:3.1.0'
    compile 'com.google.android.gms:play-services-auth:11.4.2'

这是因为 firebase-ui-authplay-services-auth 有传递依赖,并且必须与相应版本的 play-services 一起使用-验证.请参阅此说明.

This is because firebase-ui-auth has a transitive dependency to play-services-auth and must be used with the corresponding version of play-services-auth. Please see this explanation.

firebase-ui-auth
|--- com.google.firebase:firebase-auth
|--- com.google.android.gms:play-services-auth

早期版本的 Gradle 构建工具不包含传递依赖项,因此现在版本可能与其他 play-services 版本冲突.

Earlier versions of the Gradle build tool did not include transitive dependencies so now versions can conflict with other play-services versions.

我的问题得到了解释和回答(以防有人想知道)

当您升级到 Android Studio 3.0 并将 gradle 构建工具版本更新到 3.0.0 时,依赖项的编译现在与早期版本不同.

When you upgrade to Android Studio 3.0 and update the gradle build tool version to 3.0.0, compiling of dependencies is now done differently than in earlier versions.

我最近遇到了同样的问题.我使用的这些依赖项在 Gradle 2.3.3 版中运行良好:

I recently encountered the same issue. I was using these dependencies which worked fine through Gradle version 2.3.3:

implementation 'org.apache.httpcomponents:httpmime:4.3.6'
implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'

升级到 gradle-build-version 3.0.0 后,我得到了同样的错误.深入研究,我发现 httpmime 的传递依赖与包含的文件 httpclient-android 冲突.

After the upgrade to gradle-build-version 3.0.0, I got the same error. Digint into it, I found that the transitive dependency of httpmime conflicted with the file httpclient-android was including.

说明

让我详细解释一下.早些时候,在使用 gradle-tool-version 2.3.3 时,我使用 httpclient-android 来获取和使用名为 org.apache.http.entity.ContentType.java 的类>展开 org.apache.httpcomponents:httpmime:4.3.6 的传递依赖,发现它有 org.apache.httpcomponents:httpcore:4.3.6 是同一个包我想用.但是在编译或同步构建时,它不包括 org.apache.http.entity.ContentType.java 所以我需要添加这个包含 ContentType.java 的依赖项:

Let me explain this in detail. Earlier, while using gradle-tool-version 2.3.3, I was using httpclient-android to fetch and use the class named org.apache.http.entity.ContentType.java Expanding the transitive dependencies of org.apache.httpcomponents:httpmime:4.3.6 showed that it has org.apache.httpcomponents:httpcore:4.3.6 which is the same package I wanted to use. But while compiling or syncing the build, it was excluding org.apache.http.entity.ContentType.java so I needed to add this dependency which includes ContentType.java:

implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'

之后一切正常.

一旦我将 gradle-build-version 升级到 3.0.0,事情就变了.它现在包含所有传递依赖项.因此,在使用 gradle-build-tool 3.0.0 版的最新 Android Studio 进行编译时,我的 ContentType.java 被编译了两次.一次来自 org.apache.httpcomponents:httpcore:4.3.6(这是 httpmime 的隐式传递依赖),再次来自 org.apache.httpcomponents:httpclient-android:4.3.5.1 我之前用的.

Once I upgraded the gradle-build-version to 3.0.0, things changed. It now included all transitive dependencies. So while compiling with the latest Android Studio with gradle-build-tool version 3.0.0, my ContentType.java was being compiled twice. Once from org.apache.httpcomponents:httpcore:4.3.6 (which is an implicit transitive dependency of httpmime) and again from org.apache.httpcomponents:httpclient-android:4.3.5.1 which I was using earlier.

要解决这个问题,我必须删除现有的 org.apache.httpcomponents:httpclient-android:4.3.5.1 依赖项,因为 httpmime 本身会获取所需的相关类用于我的应用程序.

To resolve this issue I had to remove the existing org.apache.httpcomponents:httpclient-android:4.3.5.1 dependency as httpmime would itself fetch the relevant class required for my application.

我的情况的解决方案:只使用所需的依赖项并删除httpclient-android

The solution for my situation: only use required dependencies and remove the httpclient-android

implementation 'org.apache.httpcomponents:httpmime:4.3.6'

请注意,这只是我的情况.您需要深入了解自己的依赖项并相应地应用解决方案.

Note that this is just the case for me. You'll need to dig into your own dependencies and apply the solution accordingly.

这篇关于无法合并 Dex - Android Studio 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆