I'm trying to add a "room" to my project.
When I try to build a project, I get an error:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
What I have already done:
Clean/Rebuild project
I added "multiDexEnabled true" in defaultConfig{}. Then I get the error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [C:\Users\user1\AndroidStudioProjects\git\mobile\app\build\intermediates\multi-dex\debug\componentClasses.jar]
(Can't read [C:\Users\user1.gradle\caches\transforms-1\files-1.1\support-core-utils-26.1.0.aar\a6c34f6784b0b6bc5c2fc7a7815426da\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/v4/content/PermissionChecker$PermissionResult.class]))
If I remove the "room" from my project, it is build without errors.
I'm using Android Studio 3, gradle build tools 3.0.0.
This is my build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
repositories {
mavenCentral()
}
android {
compileSdkVersion 23
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "trsnet.gtp2.com"
minSdkVersion 17
targetSdkVersion 23
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile files('libs/commons-codec-1.9.jar')
compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-
dependencies.jar')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support.constraint:constraint-layout:+'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
}
I was having this problem too and it took me quite a while to solve, but I finally got it. ROOM uses some of the support-v4 libraries so this is why you are getting the error that there are duplicate zip entries. In my situation, ROOM is using components from an earlier version than what I needed. So what worked for me (found here) is adding the following to the root level of the Gradle file:
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
What I found this does is it prevents libraries from including any support-v4 components, but then you have to manually include the necessary components for both ROOM and anything else you might need. If you need to find out exactly which libraries are duplicates then you can follow these instructions to look into each library and it's dependencies.
Slightly unrelated note: As of Gradle 3.0 using the compile configuration is deprecated and should be replace with implementation or api, a nice explanation can be found here.
Related
Hey guys recently I was reading an answer and I came across this
Add the following dependency to your app's Gradle file and run the application.
debugCompile 'com.amitshekhar.android:debug-db:1.0.0'
My question is this where do I paste this to?
I copied This to the build.gradle file in the android studio and I got a lot of errors saying
Error:(9, 0) Gradle DSL method not found: 'debugCompile()' Possible causes:<ul><li>The project 'DB' may be using a version of the
Android Gradle plug-in that does not contain the method (e.g.
'testCompile' was added in 1.1.0). Upgrade
plugin to version 2.3.3 and sync projectThe project 'DB'
may be using a version of Gradle that does not contain the method. Open Gradle wrapper fileThe
build file may be missing a Gradle plugin. Apply Gradle plugin
Any Pointers on how to add a dependency would be appreciated! PS The official documentation just confuses me even more so please keep the answer simple Thanks :)
You need to add the dependency inside the dependencies block in your module build.gradle not in your project build.gradle.
You can see the sample how adding the dependency from UniversalMusicPlayer sample. Here the sample of module build.gradle without the license:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.android.uamp"
minSdkVersion 17
targetSdkVersion 26
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
abortOnError true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
provided 'com.google.android.wearable:wearable:2.0.3'
compile 'com.google.android.gms:play-services-cast-framework:11.0.1'
compile 'com.google.android.support:wearable:2.0.3'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:mediarouter-v7:26.1.0'
compile 'com.android.support:leanback-v17:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.google.android.exoplayer:exoplayer:r2.5.0'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:26.1.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
Take a look at the dependencies block:
dependencies {
...
}
You need to add debugCompile 'com.amitshekhar.android:debug-db:1.0.0'
there. So it will become:
dependencies {
...
debugCompile 'com.amitshekhar.android:debug-db:1.0.0
}
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'
Go to <project>/app/ and open build.gradle file
Add the following line to the defaultConfig and dependencies sections
android {
...
defaultConfig {
...
multiDexEnabled true // ADD THIS LINE
}
}
...
dependencies {
...
implementation 'com.android.support:multidex:1.0.3' // ADD THIS LINE
}
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.
I got the same problem, adding sourceCompatibility and targetCompatibility to my build.gradle helped me:
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
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' }
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'
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.
while creating Flutter Project, I encountered this issue. What I did is, opened MyProject/android/app/build.gradle file and added multiDexEnabled true inside defaultConfig tag as given below:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "Your Application ID Here"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
When the same issue appeared, my build.gradle already had the following was already there:
android {
...
defaultConfig {
...
multiDexEnabled true
}
}
...
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
I cleaned the project, and then run build again, and the issue was gone.
in my case i change all com.android.support: libraries to 27.1.0 and it works
This is my app level build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 16
targetSdkVersion 24
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'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5#aar'
compile 'org.jsoup:jsoup:1.10.2'
compile 'com.google.firebase:firebase-messaging:10.2.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
I have tried:
Building/Cleaning the project.
Invalidate Caches/Restart.
Enabling multidex gives new errors and does not work.
Version 9.6.1 of the firebase-messaging library builds the apk but app crashes on start up.
Updated the versions of google support repository/play services.
I use only the messaging library so different version numbers are not the problem. Adding the firebase-core library seems to be of no use.
Used API level 25 as well.
Needless to say, I double-checked the project-level build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have searched and tried many related answers on stackoverflow but failed to come up with a solution.
Possible solution:
Version 9.6.1 builds the apk but crashes the app on startup. Maybe the problem is with the version.
Here is the error:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zze;
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
My project was working fine until I added the Facebook dependency.
I've started getting this error.
I've read many question, the problem seems to be related to MultiDex.
But none of the solutions worked for me
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1
Even after I remove what I've added, it still show and also gradle seems to be taking a lot of time while building than usual
Here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "net.ciblo.spectrodraft"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.pnikosis:materialish-progress:1.5'
compile 'com.nineoldandroids:library:2.4.+'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
}
Adding the following code to build.gradle app module solved my problem
android{
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
//...
compile 'com.android.support:multidex:1.0.0'
}
you can selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:
compile 'com.google.android.gms:play-services:8.4.0'
with these lines:
compile 'com.google.android.gms:play-services-fitness:8.4.0'
compile 'com.google.android.gms:play-services-wearable:8.4.0'
==> to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.
Adding the following in build.gradle fixed the issue for me,
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
//...
}
This horrendous recurring issue hit me again recently. The gradle build stalls permanently at app:transformClassesWithDexForDebug, just running for hours and never completing. This time I fixed it by removing all references to 'fabric', a new layer of Crashlytics being pushed on us.
//apply plugin: 'io.fabric' //REMOVE
//classpath 'io.fabric.tools:gradle:1.26.1' //REMOVE
I'm using the YouTube SDK to play videos in a viewpager. As soon as I run the app, this error is thrown:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/youtube/player/internal/u.class
Manifest.xml:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.xxxxx.www.xxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
mavenLocal()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.thefinestartist:ytpa:1.2.1'
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
compile 'com.mxn.soul:flowingdrawer-core:1.2.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.13.0'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.xgc1986.android:parallaxpagertransformer:1.0.3'
compile('com.github.afollestad.material-dialogs:core:0.8.5.7#aar') {
transitive = true
}
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
}
I can't include
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
as viewpager uses support library v4
That error comes when any of your jar dependency have same class. Make sure you have not added support jar both as gradle and jar dependency. There might be duplicate references to the same API.
Try ./gradlew yourBuildVariantName --debug from the command line. You can safely remove it from the project or from your build file(s), clean using the command ./gradlew clean and rebuild the project(repeat if necessary).
Check this related SO questions Gradle Duplicate Entry: java.util.zip.ZipException and java.util.zip.ZipException: duplicate entry during packageAllDebugClassesForMultiDex.
I observed the same issue after Android Studio upgrade to version 2.2 Preview 6
Then I deleted lines:
compile(name: 'YouTubeAndroidPlayerApi', ext: 'jar')
and
flatDir { dirs 'libs'}
from two build.gradle files and the issue is gone.
Looks like 'libs' directory is built automatically now but I'm not able to find any confirmation on Google pages.
Add
dependencies {
compile 'com.android.support:support-v4:24.2.1'
}
in build.gradle file.