ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

无法合并Dex – Android Studio 3.0

2019-09-18 09:27:11  阅读:251  来源: 互联网

标签:android-studio-3-0 android android-gradle


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

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

我试过清理和重建项目,但它没有用.任何帮助将不胜感激.

项目级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

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'

我已经尝试了所有答案,但我无法解决此错误.请帮忙.

解决方法:

向play-services-auth添加显式依赖项以及firebase-ui-auth依赖项:

// 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-auth对play-services-auth具有传递依赖性,并且必须与相应版本的play-services-auth一起使用.请参阅this explanation.

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

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

我的问题得到解释和回答(如果有人想知道的话)

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

我最近遇到了同样的问题.我使用这些依赖项,通过Gradle版本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后,我得到了同样的错误. Digint进入它,我发现httpmime的传递依赖与httpclient-android文件冲突包括.

描述

让我详细解释一下.早些时候,在使用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的依赖项:

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我之前使用的.

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

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

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

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

标签:android-studio-3-0,android,android-gradle
来源: https://codeday.me/bug/20190918/1810921.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有