gpt4 book ai didi

android - 无法合并 Dex - Android Studio 3.0

转载 作者:IT王子 更新时间:2023-10-28 23:56:46 26 4
gpt4 key购买 nike

当我在稳定 channel 中将我的 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-authplay-services-auth 有传递依赖,必须与对应版本的 play-services 一起使用-auth。请看 this explanation .

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

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

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

当您升级到 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 后,我得到了同样的错误。仔细研究一下,我发现 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 - 无法合并 Dex - Android Studio 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46949761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com