I upgraded the android studio 2.x.x to android studio 3.0.1 after importing the project gradle building is successful. But when installing app showing the error message
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
my app grdle is given below
Why it's showing this error and how to fix it? unable to install the app on the emulator.
Already tried the clean and rebuild option in android studio but it doesn't fix the issue
Try with the following
If your minSdkVersion is set to 21 or higher
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
...
}
if your minSdkVersion is set to 20 or lower,
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
If this does not resolve, try through these posts post 1 , android_dev or post 2
To remove this Dex issue just implement one dependency.
This issue occur when we are using multiple different service from the same server. Suppose we are using ads and Firestore in a project and both have a repository maven. so we need to call different data with on repository we need dex dependency to implement.
The new update Dependency:-
implementation 'com.android.support:multidex:1.0.3'
or use testCompile inside compile such as :
implementation 'com.google.android.gms:play-services-ads:15.0.1'
testCompile 'com.google.firebase:firebase-firestore:17.0.1'
and also make multiDexEnabled true;
100 % it will work !
android studio was getting build error while build execution with following:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex"
My app:build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.pdroid.foodieschoice"
minSdkVersion 16
targetSdkVersion 25
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.constraint:constraint-layout:1.0.2'
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
testCompile 'junit:junit:4.12'
}
configurations.all {
resolutionStrategy {
force 'com.android.support:appcompat-v7:26.0.1'
force 'com.android.support:support-compat:26.0.1'
force 'com.android.support:support-core-ui:26.0.1'
force 'com.android.support:support-annotations:26.0.1'
force 'com.android.support:recyclerview-v7:26.0.1'
}
}
apply plugin: 'com.google.gms.google-services'
any solutions
Edit: i have done with sample through firebase github site and solved
For Cordova based project, run cordova clean android before build again, as #mkimmet suggested.
This error happens when you add an external library which may not be compatible with your compileSdkVersion .
Be careful when you are adding an external library.
I spent 2 days on this problem and finally it got solved following these steps.
Make sure all your support libraries are same as compileSdkVersion of your build.gradle(Module:app) in my case it is 26.
In your defaultConfig category type multiDexEnabled true. This is the important part.
Go to File | Settings | Build, Execution, Deployment | Instant Run and try to Enable/Disable Instant Run to hot swap... and click okay
Sync Your project.
Lastly, Go to Build | click on Rebuild Project.
Note: Rebuild Project first cleans and then builds the project.
Try to add this in gradle
android {
defaultConfig {
multiDexEnabled true
}
}
Resolution:
Refer to this link: As there are various options to shut the warning off depending on the minSdkVersion, it is set below 20:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
... }
dependencies { compile 'com.android.support:multidex:1.0.3' }
If you have a minSdkVersion greater than 20 in your build.gradle set use the following to shut down the warning:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
... }
Update dependencies as follows:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Again the only difference is the keywords in dependencies:
minSdkVersion below 20: use compile
minSdkVersion above 20: use implementation
I hope this was helpful, please upvote if it solved your issue, Thank you for your time.
Also for more info, on why this occurs, please read the first paragraph in the link, it will explain thoroughly why? and what does this warning mean.
Simply try doing a "Build -> Clean Project". That solved the problem for me.
For me, adding
multiDexEnabled true
and
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
into the app level Build.gradle file solved the issue
Go to your module level build.gradle file and add the following lines to the code
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
That solved the problem easily. Check this documentation
Use multiDexEnabled true as below.
{
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
and
implementation 'com.android.support:multidex:1.0.3'
this Solution worked for me.
I tried many solutions as mentioned above including the multiDexEnabled true but none of that worked for me.
Here is the solution which worked for me - copy this code in app\build.gradle file
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support' && requested.name != 'multidex') {
details.useVersion "${rootProject.ext.supportLibVersion}"
}
}
}
Make sure to run gradlew clean before running the code
Same thing happened to me, figured out that I was in the middle of updating to AS 3.0.1 and after I did the update, cleaned and rebuilt the app, everything was fixed.
For me what fixed this error was changing one line in my app's gradle dependencies.
from this:
compile('com.google.android.gms:play-services-gcm:+') {
force = true
}
To this:
compile('com.google.android.gms:play-services-gcm:11.8.0') {
force = true
}
Also be sure your app is subclassing MultiDexApplication
import android.support.multidex.MultiDexApplication
class App : MultiDexApplication()
or if not subclassing Application class, add to AndroidManifest.xml
<application
android:name="android.support.multidex.MultiDexApplication"
This is what works for me. clean prepare and run.
cordova clean android;
ionic cordova prepare andriod;
ionic cordova run andriod;
hope it helps.
I also got the similar error.
Problem :
Solution :
Main root cause for this issue ismultiDex is not enabled.
So in the Project/android/app/build.gradle, enable the multiDex
For further information refer the documentation: https://developer.android.com/studio/build/multidex#mdex-gradle
Are you in between SDK or platform updates?
If yes complete those completely and then try to continue.
I normally update the individual packages that need to be updated as to taking the entire update which could go up to 2.5 GB sometimes. Doing this complete update sometimes fails. I had a number of SDK updates once I upgraded to Android Studio 3.0 and was getting the above error since all packages had not been updated. Once I updated all packages the above error was gone.
In my case changing firebase library version from 2.6.0 to 2.4.2 fixed the issue
For me, the problem was the use of Java 1.8 in a module, but not in the app module. I added this to the app build gradle and worked:
android{
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Same problem. I have enabled multidex:
defaultConfig {
applicationId "xxx.xxx.xxxx"
minSdkVersion 24
targetSdkVersion 26
multiDexEnabled true
I have cleared cache, ran gradle clean, rebuild, make, tried to make sure no conflicts in imported libraries (Removed all transitive dependencies) and made all updates. Still:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Turns out the build did not like:
implementation 'org.slf4j:slf4j-android:1.7.21'
When the version of Android Studio is 3.0.1, Gradle Version is 4.1 and Android PluginVersion is 3.0.0, it will encounter this problem. Then I downgrade Gradle Version is 3.3, Android Android is zero, there is no such problem.
I had this when requested SDK version didn't match the dependencies. You can click the line highlighted and fix this clicking the red light bulb. No need to find the actual version, just let the IDE figure it out for you. And add google repo to maven config.
I was receiving the same error and in my case, the error was resolved when I fixed a build error which was associated with a different build variant than the one I was currently building.
I was building the build variant I was looking at just fine with no errors, but attempting to debug caused a app:transformDexArchiveWithExternalLibsDexMergerForDebug error. Once I switched to build the other build variant, I caught my error in the build process and fixed it. This seemed to resolve my app:transformDexArchiveWithExternalLibsDexMergerForDebug issue for all build variants.
Note that this error wasn't within the referenced external module but within a distinct source set of a build variant which referenced an external module. Hope that's helpful to someone who may be seeing the same case as me!
I Have Done and fixed this issue by just doing this jobs in my code
Open ->build.gradle
Change value
from
compile 'com.google.code.gson:gson:2.6.1'
to
compile 'com.google.code.gson:gson:2.8.2'
1)Please add multiDexEnabled true
2)if you get compilation error then check your app level build.gradle weather same dependencies are implemented with different versions.
3)Remove one if you find same dependencies.
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
hope it works fine :) Happy Coding
The easiest way to avoid suck kind of error is:
-Change library combilesdkversion as same as your app compilesdkversion
-Change library's supportLibrary version as same as your build.gradle(app)
I have this error whenever i try to create an APK for the app.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/text/TextUtilsCompat.class
The app run in the android emulator , but when i try to build an apk i get this error.
i dont know what to change
here is the gradle code
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.companyname.gamename"
minSdkVersion 11
targetSdkVersion 23
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/support-v4-19.0.1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
}
I tryed to clean rebuild an run the prject but i still have the same problem,
I've read that it's depencdencies problem. but can't figure wich one to remove.
First, never use a plus dependency.
services:+'
Also don't compile all the Play Services, only setup ones you really need.
https://developers.google.com/android/guides/setup#split
Secondly, stop using jar files and go find the correct libraries using Maven Central (or the supporting documentation for those libraries) and use the other way to compile through Gradle.
Your jar files have overlapping classes and therefore you have errors
While you're at it...
Dagger 1 is being deprecated for Dagger 2
NineoldAndroids has stopped being maintained, so best to find some other way to use the code you need it for
Your support libraries need to match the compileSdk version
I'm relatively new to Android programming and I am trying to create a Google Maps project. I used the template option in Android Studio, and I added the key for the API.
I haven't added any of my own code and left the template code as is because I just wanted to run the code and see what it looks like, however, I keep getting a multi dex error when I try to run this on the emulator causing the build to fail. It's weird to me that I am getting this error because I haven't added ANY code at all and am using what the Google Maps template has from Android Studio.
Anyone know why this error shows up on a brand new project? The error I see is pasted below.
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_91\bin\java.exe'' finished with non-zero exit value 2
as quoted below:
Your probably compiling all of the play-services API's using compile 'com.google.android.gms:play-services:9.2.0'... Now we can selectively compile API's to avoid dex limit of 64K. For Google Maps use com.google.android.gms:play-services-maps:9.2.0... – Loki Jul 1 at 19:01
Answer from Loki worked and was very simple to do.
setting up google play services
Go through this link just add the dependencies which you want in your application.
This will prevent 64k exceeding error.
Happy coding.
For those who tried all the above methods and failed. Try changing the mini sdk version to 21 in the build.gradile file. For me it was on 16 and when I changed it to 21 the multidex error was gone for good.
minSdkVersion 21
The issue is you currently have a high number of methods. There can only be 65536 methods for dex. You can try enabling multiDex by editing your build.gradle file.
android {
//stuff
defaultConfig {
...
// Enable multiDex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Also, oops as the poster above mentioned in your manifest you also need to add that you are using the multidex class from the multidex support library.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.dexapp">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
Change your Gradle build configuration to enable multidex
android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc2"
defaultConfig {
applicationId "com.try.app"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
In your manifest add the MultiDexApplication class from the multidex support library to the application element.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Note: Visit https://developer.android.com/studio/build/multidex.html for more info.
Set property multiDexEnabled to true in defaultConfig. This error occurs when method references increase the limit of 65k. Check Google Play Service APIs.
android{
...
defaultConfig {
...
multiDexEnabled true
}
...
}
Here is a good source to get started with Google Maps Android API
I removed the dependencies as suggested by Loki and it works.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.android.gms:play-services-maps:9.4.0'
}
I have this error :
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzrf.class
I want to add google play services to my project so i put this line in build.gradle file :
compile 'com.google.android.gms:play-services:7.8.0'
So I had to enable multidex and I followed android doc, adding this in build.gradle :
compile 'com.android.support:multidex:1.0.1'
and
multiDexEnabled true
I add this in android manifest :
<application
...
android:name="android.support.multidex.MultiDexApplication">
But I have the error I wrote above. I've found a lot of questions relative to this problem (app:packageAllDebugClassesForMultiDex) but not with that (duplicate entry: com/google/android/gms/internal/zzrf.class).
I tried some solutions like remove some google libraries but I don't know what refers to internal/zzrf.class.
Here is my gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "fr.djey.testgoogleplus"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.android.support:multidex:1.0.1'
}
I faced same problem. In my case I used home made Android library used by My Android app. Which means 1 project with 2 separate modules, while the app module depends on the library module.
Both have support of multidex. The root cause was inconsistency between google play services version. In the app module I used 7.8.+ and in the library I used 8.1.+. So I just updated both to same 8.1.+ and that fixed for me. So my answer is to check all the libs you depend on and may 1 of them using google play services version below yours.
Delete all files under build folder of that project. In my case, it is the jar file of the whole google play conflict with the jar file of only ads service.
As I said in the comment : I created another project and just did the same things : putting google play services and multidex, the problem didn't appear anymore.