java.util.zip.ZipException with spongycastle LICENSE.class - android

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.

Related

app:transformClassesWithJarMergingForDebug can't resolve

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

Apache POI Libraries error in Android Studio..?

I added 5 jar files of Apache POI so that I can save an text as .docx document but I can't run the application first I had 210 error in the grade now i have this error can someone please help me ..!? i followed this example
https://www.tutorialspoint.com/apache_poi_word/apache_poi_word_quick_guide.htm
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.mike.textword"
minSdkVersion 19
targetSdkVersion 25
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'
}
}
}
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'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile files('libs/dom4j-1.6.jar')
compile files('libs/poi-3.16-beta2.jar')
compile files('libs/poi-ooxml-3.16-beta2.jar')
compile files('libs/poi-ooxml-schemas-3.16-beta2.jar')
compile files('libs/xmlbeans-2.6.0.jar')
compile 'com.android.support:multidex:1.0.1'
}
and now i have this error!
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class
Currently Apache POI will not work on your Android Phone out of the box due to various problems that you will run into when using the libraries from Apache POI directly. Android is more strict about duplicate classes as part of the jar-files and unfortunately XmlBeans has such duplicate classes in it's jar-file.
There are two projects that try to make it possible to use Apache POI on Android:
https://github.com/andruhon/android5xlsx (for Android 5) and https://github.com/andruhon/AndroidReadXLSX (for Android 4), both are currently still based on Apache POI 3.12
https://github.com/centic9/poi-on-android/ (for Android 5, maintained by me), which can be more easily recompiled with newer versions of POI, e.g. it uses 3.16-beta2 currently
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class
It means that you are adding this class twice or more.
Check all you jars files to remove it.

Guava library duplicate entry error

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.

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry issue

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

Android with Gradle (Java finished with non-zero exit value 2)

This is my .gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.test.test"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.mcxiaoke.volley:library:1.0.15'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.17'
}
When I try to run my Android app, I get the next error:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 2
I get this error when I add to gradle file the jackson library.
Googling some time, I've found that jackson library is compatible with android apps, and It's faster than other libraries as gson.
How I can solve it?
I'm an Android beginner.
I think you should change your java JDK change jvm v8 for jdk7. This link can help you:
Is it possible to use Java 8 for Android development?
Other possible issue its dependency error, clean gradle before build. And change your jackson library for this:
compile 'com.fasterxml.jackson.core:jackson-databind:2.2.+'
compile 'com.fasterxml.jackson.core:jackson-core:2.2.+'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.+'
Uncomfortably this issue may have several reasons. In my case, it was because of the max line number is exceeded. It is so annoying that the message Android Studio shows does not mean anything, but somehow i found the solution as below:
https://developer.android.com/tools/building/multidex.html
You have to create a class that extends MultiDexApplication, and override the following method:
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Do not forget to add "name" inside tag in your AndroidManifest file as described in the above link.
I had copied the required library inside my_project/app/libs and also added the dependency in build.gradle. So, in my case I removed the library that I had copied in my_project/app/libs. As gradle maintains all the dependency I don't have to put the library in /libs. This fixed my problem.
Maybe you have a dependency that causes incompatibility
for example:
Fixing JDK path solves the problem.
Right click on Project > Open Module settings > SDK Location > Under JDK location give path to JDK folder.

Categories

Resources