Multiple dex files define Landroid/support/v4/... error - android

I just included some Glide libraries and the Gradle builds fine.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.1.1'
testCompile 'junit:junit:4.12'
compile files('libs/glide-3.7.0.jar')
compile files('libs/glide-3.7.0-javadoc.jar')
compile files('libs/android-support-v4.jar')
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC1'
}
But I run into this:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/ActivityCompatHoneycomb;
As well as this:
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
Would appreciate any tips on getting this sorted out.

There are two dependencies causing a conflict. compile 'com.android.support:appcompat-v7:23.1.1' and compile files('libs/android-support-v4.jar')
I manually included the libs/android-support-v4.jar in the library directory since Glide requires it then removed the compile files('libs/android-support-v4.jar') dependency. The Gradle synced well after that, and the error was cleared.

Related

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug' in android + volley libraries

I've read article this in backendless and this and this in StackOverflow. But there isn't any help for me. I searched everywhere but there isn't any solution.The error is bellow
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.dex.DexException: Multiple dex files define Lcom/android/volley/VolleyError;
In build.gradle
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:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
androidTestCompile 'com.mcxiaoke.volley:library:1.0.18'
compile project(":volley")
compile 'com.mcxiaoke.volley:library:1.0.18'
}
This error will disappear when removing compile 'com.mcxiaoke.volley:library:1.0.18' in build.gradle.
What I need to be done is pass the data within app and server(localhost). To pass the string I'm using JSON. In android app using Volley libraries.
What would be I missed? Thank you
I'm searching everywhere but there aren't any references
The documentation shows that Google's official Volley artifact is available via:
compile 'com.android.volley:volley:1.0.0'
Use that instead of com.mcxiaoke.volley:library:1.0.18, which was published two years ago.
Now, you also have compile project(":volley"). I do not know why. Use either com.android.volley:volley:1.0.0 or compile project(":volley"), not both. Unless you have some specific reason for using the library module (e.g., you are forking Volley), I would recommend using the com.android.volley:volley:1.0.0 artifact.

Issue regarding duplicate android-support-v4.jar

I am facing issue while building the apk..
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/widget/ViewDragHelper$Callback.class
The Dependencies i have added is :
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'
})
compile files('libs/PGSDK_v1.0.1.jar')
compile files('libs/gcm.jar')
compile files('libs/utilities.jar')
compile files('libs/volley.jar')
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.moengage:moe-android-sdk:7.4.01'
compile 'com.google.android.gms:play-services-gcm:10.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
Remove this dependency compile files('libs/gcm.jar')
You already have compile 'com.google.android.gms:play-services-gcm:10.0.1'
EDIT
Internally some library depends on support-v4 with x- version so gradle link that with your project. Check which artifact having support-v4 and manually exclude support-v4 from that artifact like this.
compile ('com.android.support:appcompat-v7:25.3.1') {
exclude module: 'support-v4'
}
It's better to use group name with artifact and version to compile instead of jars if artifact is available in any repository.

Cannot build APK - DexException

When I'm building my project by "Run (applicaton)" build-in function - everything's fine, I can test my app through phone, but I want to create standalone application by gradle.
I'm using gradle :client:clean :client:assemble task, and that's my output:
Dex: Error converting bytecode to dex:sesWithDexForDebug
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
By this link I've searched for some dependencies between my modules. I checked, that appcompat-v7 and design library have support-v4 library build-in, so I removed it from design library.
My build.gradle file:
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'
})
//Support Design
compile ('com.android.support:appcompat-v7:23.4.0')
compile ('com.android.support:design:23.4.0') {
exclude module: 'support-v4'
}
//Butter Knife
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
//Retrofit
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
//JSON Utils
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
//Dagger 2
compile 'com.google.dagger:dagger:2.9'
annotationProcessor 'com.google.dagger:dagger-compiler:2.9'
provided 'javax.annotation:jsr250-api:1.0'
//Android Plot
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
//Apache Commons
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
//RxJava
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
//Tests
testCompile 'junit:junit:4.12'
}
How can I fix it?
Regards
EDIT
I added multiDexEnabled true, and it gaves me another error:
Error:Execution failed for task ':client:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/hardware/display/DisplayManagerCompat$JellybeanMr1Impl.class
When your app has over 64k methods, you must enable Multidex. Usually this happens when a large number of libraries are used.
To get around this, enable Multidex in your build.gradle
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 25
multiDexEnabled true
}
...
}
Read more about Multidex here.
Just change this attribute
multiDexEnabled false to multiDexEnabled true

Execution failed for task ':app:transformClassesWithDexForDebug' in small app

I am trying to build an Android project (it is a small project), and I am getting this error in Travis:
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
I am aware I can fix this problem by enabling multiDex, however I don't think this error should happen in my case, as I don't believe the project and its dependencies surpass the method limit for multiDex.
Here are the dependencies in my build.gradle file:
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 project(':geth')
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:design:25.1.0'
testCompile 'junit:junit:4.12'
}
Any ideas?
Thanks
You exceeded 65536 methods. Maybe this :geth project is too big?
You can turn multidexing on, more info here:
https://developer.android.com/studio/build/multidex.html
You can check what part of your project taking too much method indexes with:
https://github.com/KeepSafe/dexcount-gradle-plugin

generate signed APK error : java.util.zip.ZipException

I use my samsung A5 for testing app and the project is working correctly on my phone, but not working on other phones. so I want to Generate signed APK from my project. but there was an exception error:
Error:Execution failed for task '::transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/daimajia/androidanimations/library/BaseViewAnimator;
I googled the error and these code remove that error:
multiDexEnabled true
and
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
but now there is another exception:
Error:Execution failed for task ':transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/daimajia/androidanimations/library/BaseViewAnimator.class
I think this might be because of libraries that I use, but have no idea how to handle it. below is all libraries in build.gradle :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
//for compiling card view
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
//for sticky header
compile 'com.github.carlonzo.stikkyheader:core:0.0.3-SNAPSHOT'
compile 'com.github.ksoichiro:android-observablescrollview:1.5.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.melnykov:floatingactionbutton:1.0.7'
compile 'com.ogaclejapan.smarttablayout:library:1.6.1#aar'
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.6.1#aar'
compile 'me.drakeet.materialdialog:library:1.3.1'
compile files('libs/volley.jar')
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
//Sweet Alert Dialog
compile 'cn.pedant.sweetalert:library:1.3'
compile 'org.apmem.tools:layouts:1.10#aar'
}
A few things...
First of all, I'd remove most of the 3rd party libraries you are including. For example,
//for sticky header
compile 'com.github.carlonzo.stikkyheader:core:0.0.3-SNAPSHOT'
compile 'com.github.ksoichiro:android-observablescrollview:1.5.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.melnykov:floatingactionbutton:1.0.7'
all of those are covered by the Design Support Library from Google
From the names I think you can also remove
compile 'com.ogaclejapan.smarttablayout:library:1.6.1#aar'
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.6.1#aar'
compile files('libs/volley.jar') should be replaced with compile 'com.android.volley:volley:1.0.0'
and I'd also remove
//Sweet Alert Dialog
compile 'cn.pedant.sweetalert:library:1.3'
compile 'org.apmem.tools:layouts:1.10#aar'
Many of those projects you are including haven't been worked on in over 2 years.
Try to still with the support libraries from Google. You'll get most of this from the Design support library.
Last point. You are getting the Dex errors because the app is including all of these libraries and passing the 64k method limit. I suggest enabling proguard to remove un-used code and reduce the method count of your project.

Categories

Resources