I have Android Studio Beta. I created a new project with compile my old modules but when I tried launching the app it did not launch with the message:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
But I don't know how to solve this error. I googled this for hours but with no success.
My project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath "io.realm:realm-gradle-plugin:3.7.1"
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
}
My app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "parad0x.sk.onlyforyou"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
compileOptions {
targetCompatibility 1.7
sourceCompatibility 1.7
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
lintOptions {
checkReleaseBuilds false
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleCompatible
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile project(path: ':loginregisterview')
}
And my module gradle:
apply plugin: 'com.android.library'
apply plugin: 'realm-android'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
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.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.github.bumptech.glide:glide:4.0.0'
testCompile 'junit:junit:4.12'
compile project(path: ':parser')
}
My second module:
apply plugin: 'com.android.library'
apply plugin: 'realm-android'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
realm {
syncEnabled = true
}
useLibrary 'org.apache.http.legacy'
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'junit:junit:4.12'
// compile 'com.android.support:appcompat-v7:23.1.0'
// compile 'com.fasterxml.jackson.core:jackson-core:2.9.0'
// compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
// compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
compile 'com.google.code.gson:gson:2.6.2'
}
____________finding_________
When I did not import the second module (parser) the app did not crash on dex but when the module was not imported app did not work. :D :D
I agree with Chris-Jr. If you are using Firebase to embed your AdMob ads (or even if you are not) the play-services-analytics includes the play-services-ads even though you don't add that as a dependency. Google have obviously made a mistake in their 11.4.0 roll-out as the analytics is including version 10.0.1 of ads, not 11.4.0 (the mouse over hint in the gradle shows this).
I manually added compile 'com.google.android.gms:play-services-ads:11.4.0' at the top which worked, but only after I disabled Instant Run: http://stackoverflow.com/a/35169716/530047
So its either regress to 10.0.1 or add the ads and disable Instant Run. That's what I found if it helps any.
One of possible root causes: duplicate transient dependencies that weren't properly handled by Android Studio import of multi-module projects. Check your list and remove them. For me, the fix was literally this:
I had the same problem when I update from
com.google.android.gms:play-services:11.2.2
tocom.google.android.gms:play-services:11.4.0
. This solved it for me:In my case, Unfortunately, neither Michel's nor Suragch's solutions worked for me.
So I solved this issue by doing the following:
In gradle:3.0 the compile configuration is now deprecated and should be replaced by implementation or api. For more information you can read here You can read the official docs at Gradle Build Tool
it's better to use implementation or api rather compile
just replace compile with implementation, debugCompile with debugImplementation, testCompile with testImplementation and androidtestcompile with androidTestImplementation
For example: Instead of this
use like this
After that
Hope it will helps !
Deleting
.gradle
as suggested by Suragch wasn't enough for me. Additionally, I had to perform aBuild > Clean Project
.Note that, in order to see
.gradle
, you need to switch to the "Project" view in the navigator on the top left:In my case a library makes this problem, library was successfully added to project but when i run my app it shows me this error. So if this happens to you too, you can go to github and check issues or raise new issue. If you do not find any solution regarding the library i suggest you to replace it.