问题
I made:
- In "Settings"->"Android SDK"->"SDK Tools" Google Play services is checked and installed v.46
- Removed folder /.gradle
- "Clean Project"
- "Rebuild Project
Error is:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.asanquran.mnaum.quranasaanurdutarjuma"
minSdkVersion 15
targetSdkVersion 26
versionCode 3
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-ads:11.4.2'
compile 'com.github.barteksc:android-pdf-viewer:2.3.0'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.google.firebase:firebase-ads:11.4.2'
compile 'com.google.firebase:firebase-messaging:11.4.2'
compile 'com.google.firebase:firebase-storage:11.4.2'
apply plugin: 'com.google.gms.google-services'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Please help me what should I do now
Please don't mark it duplicate I've tried almost all the solutions
回答1:
I know it's too late to update.I had same issue on my project.
Possible Reasons
- If you have added module in your project and that module has support libraries or any google play services libs which has different version then your app.
- If you are using any open source library in your project and that library internally using any of libraries that your are also using in your project.
Solutions
- If it is case 1 in your project then update your library versions and make it same in your project and module.
Check your dependencies tree using below command and see if any mismatch in dependencies.
./gradlew :app:dependencies
You can exclude particular module from any dependencies like below.
implementation('com.google.android.ads.consent:consent-library:1.0.4') { transitive = true exclude group: "com.android.support" }
In above example, It will exclude the com.android.support group from consent-library dependencies.
You can also remove particular module as well.
compile ('junit:junit:4.12'){ exclude group: 'org.hamcrest', module:'hamcrest-core' }
In above example it will exclude hamcrest-core from org.hamcrest.
回答2:
I got the same problem, adding sourceCompatibility
and targetCompatibility
to my build.gradle
helped me:
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
回答3:
I was having a fit with this, and none of the answers I found worked. Finally found a solution -- sharing it here although I can't tell you definitively how to find which is the offending dependency -- maybe you'll have to do some trial and error.
In my build.gradle (Module:app) I added this exclude clause:
compile ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')
{ exclude module: 'support-v4' }
回答4:
I did exact as the hint in the image except changed 11.0.4 to 11.8.0
compile 'com.google.android.gms:play-services-base:11.8.0'
compile 'com.google.android.gms:play-services:11.8.0'

回答5:
in my case i change all com.android.support: libraries to 27.1.0 and it works
回答6:
I think it was due to Android Studio's latest version (at that time). I tried it after a long time then the issue gone.
来源:https://stackoverflow.com/questions/46977267/com-android-builder-dexing-dexarchivemergerexception-unable-to-merge-dex-andr