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

查看:84
本文介绍了无法合并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.

推荐答案

将显式依赖项与firebase-ui-auth依赖项一起添加到play-services-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-auth的相应版本一起使用.请参阅此说明.

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天全站免登陆