java Android Studio 3.0 无法合并dex
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46980900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio 3.0 Unable to merge dex
提问by Cody Kolbert
Just Updated android studio from 2.3.3 to 3.0 now I am having the error
刚刚将 android studio 从 2.3.3 更新到 3.0 现在我遇到了错误
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Here is my gradle file:
这是我的gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "d91.compassacademy"
minSdkVersion 19
targetSdkVersion 25
versionCode 3
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
repositories {
mavenCentral()
google()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:1.0.2'
compile('com.google.api-client:google-api-client-android:1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile 'pub.devrel:easypermissions:0.2.1'
compile project(path: ':mapviewpager')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:recyclerview-v7:25.4.0'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.google.firebase:firebase-database:11.4.2'
compile 'com.google.android.gms:play-services-auth:11.4.2'
compile 'com.google.android.gms:play-services-places:11.4.2'
compile 'com.google.android.gms:play-services:11.4.2'
compile 'com.google.firebase:firebase-storage:11.4.2'
compile 'com.google.firebase:firebase-auth:11.4.2'
compile 'com.firebaseui:firebase-ui-database:1.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
compile 'com.roughike:bottom-bar:2.1.1'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:support-vector-drawable:25.4.0'
compile 'pub.devrel:easypermissions:0.2.1'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta3'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
回答by Bamboomy
I looked up:
我抬头一望:
Error:Execution failed for task ':memDicez:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
com.android.builder.dexing.DexArchiveMergerException: 无法合并 dex
yesterday and found nothing usefull,
昨天发现没什么用
my issue is now solved,
我的问题现在解决了,
this method might get you towards a solution (it worked for me, no guarantee it works for you)
这种方法可能会让您找到解决方案(它对我有用,但不保证对您有用)
I had:
我有:
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "(my secret applicationId)"
minSdkVersion 21
targetSdkVersion 25
multiDexEnabled true
}
...
}
and
和
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'ch.acra:acra:4.9.2'
//compile 'com.google.android.gms:play-services-auth:9.0.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.koushikdutta.ion:ion:2.+'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
}
and when I changed:
当我改变时:
minSdkVersion 21
to
到
minSdkVersion 16
I got a more descriptive error message which didgive solutions via google/stack overflow.
我收到了一条更具描述性的错误消息,它确实通过 google/stack overflow 提供了解决方案。
in my case
就我而言
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
should be changed to
应该改为
compile('com.googlecode.json-simple:json-simple:1.1.1') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
You can change the minSdkVersion back to a higher value later on but decreasing it seems to give a more descriptive (or more googleable) problem (and solution)
您可以稍后将 minSdkVersion 更改回更高的值,但减少它似乎会提供更具描述性(或更可搜索)的问题(和解决方案)
cheers,
干杯,
S.
S。
回答by Adrian Borja
In your file build.gradle (Project: XXX), there is this snippet
在您的文件 build.gradle(项目:XXX)中,有这个片段
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
Previously, that is 2.3.3, then became 3.0.0 when you updated your Android Studio. Try reverting it to 2.3.3 then Resync, then wait for your Android Studio to ask to update your Gradle and gradle plugin to 3.0.0. By this time, no build issues should appear related to Merge Dex.
以前是 2.3.3,当你更新你的 Android Studio 时变成了 3.0.0。尝试将其恢复到 2.3.3,然后重新同步,然后等待您的 Android Studio 要求将您的 Gradle 和 gradle 插件更新到 3.0.0。此时,应该不会出现与 Merge Dex 相关的构建问题。
回答by Varun Chandran
My issue was fixed by changing the minimal SDK to 16 and target SDK to 25, and adding multidexenabled=true
in default.config
. Add the follwing to in app/build.gradle
:
我的问题是固定的,通过改变最小的SDK为16和目标SDK至25,并增加multidexenabled=true
在default.config
。将以下内容添加到app/build.gradle
:
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support:design:25.+'
回答by Oleg Gryb
It started happening in my case after adding the following dependency.
添加以下依赖项后,它开始在我的情况下发生。
implementation 'com.getbase:floatingactionbutton:1.9.0'
I've tried all suggestions published here and in other places, but nothing has worked.
我已经尝试了这里和其他地方发布的所有建议,但没有任何效果。
I've tried then a common solution that helped in many other cases and it worked. I've simply used "Sync project with gradle files" from the following menu that can be found in Tools.
然后我尝试了一个通用的解决方案,该解决方案在许多其他情况下都有帮助,并且奏效了。我只是从以下菜单中使用了“将项目与 gradle 文件同步”,该菜单可以在工具中找到。
回答by Youness
multiDexEnabled true
multiDexEnabled true
Example
例子
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.xx.xxx"
minSdkVersion 15
targetSdkVersion 24
versionCode 9
versionName "1.0"
multiDexEnabled true //Add this
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
} }
回答by SHAI86
Take a look in "Settings"->"Android SDK"->"SDK Tools" Google Play services is checked and installed v.46, while you there check if you need to update anything else for the new android version.
查看“设置”->“Android SDK”->“SDK 工具”Google Play 服务已检查并安装 v.46,同时检查是否需要为新的 android 版本更新任何其他内容。
Clean and Rebuild the project. It should fix the problem, if not you can try to removed the .gradle folder and clean and rebuild again.
清理并重建项目。它应该可以解决问题,如果没有,您可以尝试删除 .gradle 文件夹并再次清理和重建。
For me I also had to close all android projects and open android studio again and it worked smoothly.
对我来说,我还必须关闭所有 android 项目并再次打开 android studio,它运行顺利。
Good luck,
祝你好运,