I am trying to use guava library in my application. But I am also using chromium_webview project from github. This webview project contains guava library.
And I get the following error:
Error:Execution failed for task
':app:packageAllDebugClassesForMultiDex'. java.util.zip.ZipException:
duplicate entry: com/google/common/annotations/GwtIncompatible.class
I've looked at this and this answers already and nothing seems to work.
Here's my module's build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "my.package.name"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
jumboMode = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile files('libs/svgAndroid2-3Jan2014.jar')
compile project(':chromium_webview')
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.guava:guava:18.0'
}
I've tried the exclude method on the chromium_webview project like this:
compile (project(':chromium_webview')) {
exclude group: 'com.google.guava', module: "guava_javalib.jar"
}
and like this:
compile (project(':chromium_webview')) {
exclude module: "guava_javalib.jar"
}
Can I not use the same library again?
Is there a way to use the same library for both modules?
// ======================= EDIT:
Like #petey's comment mentioned, I tried removing just the guava library from my module and my module doesn't read the library in another module.
compile 'com.google.guava:guava:18.0'
that's the line I tried removing.
Any ideas will be really appreciated.
Thank you!!
I actually did fix this problem, forgot to post it.
So the issue here was I was using maven/gradle dependency in my project BUT the chromium_webview library was using an actual JAR file as a library.
I modified the library to use the maven/gradle dependency. Android Studio and Gradle did all the work for me and excluded the necessary classes.
So make sure they both (library and your module) use the same method.
compile 'com.google.guava:guava:18.0'
I really hope this helps someone.
Thank you.
Related
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/widget/CursorAdapter$MyDataSetObserver.class - List item
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.omairm.hoops"
minSdkVersion 14
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:+'){exclude module: 'Support-v4'}
compile files('libs/PTAdRevMob.jar')
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
Do I need to delete the CursorAdapter.class?
You should add something similar to this to your build.gradle, where the duplicate file is added to exclude
android {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
}
do i need to delete the cursoradapter.class
It's good that you are reading the error and recognize a least part of what it's telling you, but you can't just delete a class from a JAR file. The build process that Gradle goes through is only throwing the error at the first class conflict it found, and there would be more if you were to only focus on that one.
My suggestion would be to find the correct and current libraries for each of the JAR files you have and remove the jar files as you go.
Also, try to actually use a number value rather than only a plus for the version because you don't want to be using alpha / beta releases of a library that'll change every few weeks
If you search around Maven you can replace most of those JAR files
dependencies {
compile "com.android.support:appcompat-v7:26+"
// Don't use just a plus here
compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/PTAdRevMob.jar')
compile group: 'com.squareup.dagger', name: 'dagger', version: '1.2.2'
// compile group: 'com.nineoldandroids', name: 'library', version: '2.4.0'
}
It's also worth mentioning that nineoldandroids is deprecated. Since you're using minSdkVersion 14, I don't think you even need it.
Dagger has also had many releases since version 1.2 but it already includes javax inject framework (see compiled dependencies https://mvnrepository.com/artifact/com.squareup.dagger/dagger/1.2.2)
You'll definitely want to take a look at Google Play | Selectively compiling APIs into your executable too.
Note that if PTAdRevMob.jar has any classes that still conflict with any other library here, you'll still get an error, and will probably need to switch to a different Ad provider
My Gradle is :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.belajarku.gamelari"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
dexOptions {
// Prevent OutOfMemory with MultiDex during the build phase
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jni.srcDirs = []// <-- disable automatic ndk-build call
}
}
dependencies {
compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
compile ('com.android.support:multidex:1.0.1'){exclude module: 'support-v4'}
}
But when I build apk the project say me :
Error:Execution failed for task
':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
android/support/v4/database/DatabaseUtilsCompat.class
Please help me for fix it.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/database/DatabaseUtilsCompat.class
You are adding twice the same class with different versions.
compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/support-v4-19.0.1.jar')
Using com.google.android.gms:play-services:+ you are adding all packages of play services libraries which have a dependency with the support-v4.
You should update your support dependencies to the same version of compileSdkVersion. Your compileSdkVersion is 25, hence your support library should also be 25.
Don't use the whole package of Google Play service, choose what you need read from Set Up Google Play Services. For example, if you want to use google ads, add only com.google.android.gms:play-services-ads:11.0.4. You need to change your dependencies like this:
dependencies {
...
// only use google ads from google service.
compile 'com.google.android.gms:play-services-ads:11.0.4'
compile 'com.android.support:support-v4:25.3.1'
...
}
Then you can disable your multidex by setting multiDexEnabled false or commenting it and removing compile ('com.android.support:multidex:1.0.1') from your dependencies.
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 am trying to include two different 3rd party libs that both seem to include different versions of Spongy castle. Both are included via compile statements in my build.gradle and one is included as an AAR (#aar) while the other is included as normal.
When I try to compile the debug buildType with these 2 libs (sync doesnt show a problem). I see the following,
Error:Execution failed for task
':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
org/spongycastle/LICENSE.class
Been searching around for how to resolve this issue while keeping both the libraries (as both are needed) but have been unable to find a way to do that. Any help from an advanced Android dev or a gradle expert would be greatly appreciated.
Thanks!
[build.gradle]
apply plugin: 'com.android.application'
repositories {
maven { url 'http://mobile-sdk.jumio.com' }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
packagingOptions {
pickFirst 'org/spongycastle/x509/CertPathReviewerMessages.properties'
pickFirst 'org/spongycastle/x509/CertPathReviewerMessages_de.properties'
}
defaultConfig {
applicationId "com.example.me.license"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile "com.jumio.android:jumio-mobile-sdk:1.9.0#aar"
compile 'com.worldpay:cse-android-sdk:1.0.2'
}
This is what happens if developers include their dependencies directly. The bad guy here is jumio-mobile-sdk. This package includes classes of com.madgag.spongycastle directly, instead of specifying them in a pom as it should be done.
Luckily for you, the other package is set up correctly, so you should be able to exclude spongycastle from it:
compile ('com.worldpay:cse-android-sdk:1.0.2'){
exclude group: 'com.madgag.spongycastle'
}
Now imagine both packages would've included the classes directly. The would've been no other possibility then to manually edit the files. This is why I hate it if someone does what the guys of jumio are doing. If you have the contacts, tell them to prepare their package for dependency systems, so this problem won't arise again.
I am struggling to run a basic Mapsforge application. I have added all its required jar files to project and gradle. But i am not able to run application. Getting following error:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: org/mapsforge/map/reader/Way.class
Here is my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "test.mapsforge"
minSdkVersion 14
targetSdkVersion 21
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.0'
compile files('libs/mapsforge-core-0.5.1.jar')
compile files('libs/mapsforge-map-0.5.1.jar')
compile files('libs/mapsforge-map-android-0.5.1.jar')
compile files('libs/mapsforge-map-awt-0.5.1.jar')
compile files('libs/SwingMapViewer-0.5.1.jar')
}
Folder structure
I have tried adding multiDexEnabled true in gradle config but didnt worked
Is there a reason you need to multidex? The decencies seem somewhat scarce and unless they are packed with methods I don't see how you would get past the 65k method limit. I also don't see a dependency for compile 'com.android.support:multidex:1.0.0' Please check https://developer.android.com/tools/building/multidex.html or try not using ultidex. You also may need to extend MultiDexApplication instead of a regular Application. I think your issue is really a duplicate dependency and not aa dex limit. have you tried gradle :app:dependencies?
I face same error too. when I delete swing map viewer every thing work fine even without using multiDexEnabled true