42 android android-gradle-plugin android-studio-3.0
当我在稳定通道中将Android Studio更新为3.0并运行项目时,我开始收到以下错误.
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Run Code Online (Sandbox Code Playgroud)
我试过清理和重建项目,但它没有用.任何帮助将不胜感激.
项目级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
}
Run Code Online (Sandbox Code Playgroud)
应用程序级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'
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有答案,但我无法解决此错误.请帮忙.
Bha*_*iya 30
添加显式依赖项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'
Run Code Online (Sandbox Code Playgroud)
这是因为firebase-ui-auth它具有传递依赖性,play-services-auth并且必须与相应的版本一起使用play-services-auth.请看这个解释.
firebase-ui-auth
|--- com.google.firebase:firebase-auth
|--- com.google.android.gms:play-services-auth
Run Code Online (Sandbox Code Playgroud)
早期版本的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'
Run Code Online (Sandbox Code Playgroud)
升级到gradle-build-version 3.0.0后,我得到了同样的错误.Digint进入它,我发现httpmime与文件冲突的传递依赖httpclient-android包括.
描述
让我详细解释一下.早些时候,在使用gradle-tool-version 2.3.3时,我httpclient-android用来获取和使用名为org.apache.http.entity.ContentType.java
Expanding的传递依赖关系的类,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'
Run Code Online (Sandbox Code Playgroud)
之后一切都很好.
一旦我将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'
Run Code Online (Sandbox Code Playgroud)
请注意,这只是我的情况.您需要深入了解自己的依赖关系并相应地应用解决方案.
Pab*_*nso 14
首先,我按照之前的评论中的建议启用了multidex.
然后,如果错误仍然存在,请打开Gradle控制台(单击"消息"部分左侧的"显示控制台输出"图标),然后单击链接以使用"调试/信息/堆栈"选项重新编译.这将显示有关错误的更多详细信息.
在我的情况下,错误"无法合并dex"是由"com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0"中的重复条目引起的.
我手动从项目中删除了冲突的库并执行了"重建项目"(强制重新加载库).这解决了这个问题.
| 归档时间: |
|
| 查看次数: |
49369 次 |
| 最近记录: |