Hi I am getting following error while running my android project :
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
I have searched about this issue on internet, differenet type of solutions provided few of them as below :
1] Enable multidex, (by doing `multiDexEnabled true`),
2] Remove support library v4 as v7 comes with it, (I am using only v7),
3] Increase jvm heap size through gradle or through gradle.properties,
2] Do not use multiple playstore library versions (Which I am not using already)
All above started when I added dependecy for Apache POI in gradle as follows :
dependencies {
....
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.14'
}
None of the above worked in my case. Why this is happening & what is reliable solution.
There are a few projects available which try to work around a number of issues when using POI on Android.
Please take a look at the sample project https://github.com/centic9/poi-on-android/ which allows to build a single jar-file for POI on Android. It removes the duplicates and also fixes a few other issues with prohibited package names and others.
Another project in that area is https://github.com/andruhon/android5xlsx, however it only supports an older version of POI currently.
In your Gradle Compile with support:multidex and add also dexOptions
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
..............
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
//incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//Your Dependencies
compile 'com.android.support:multidex:1.0.1'
}
In Your AndroidManifest.xml add this lines android:name
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>
If you have using the play service library than replace with
compile 'com.google.android.gms:play-services:+'
Instead OF
compile 'com.google.android.gms:play-services-maps:8.4.0' //or other
After doing some other reading I found out there are issues with using poi library in android, see link below :
https://bz.apache.org/bugzilla/show_bug.cgi?id=59268#c0
Project at https://github.com/andruhon/android5xlsx has reduced library versions for both poi.jar & poi-ooxml.jar, import these in your libs folder & include following code in your gradle :
compile fileTree(include: ['*.jar'], dir: 'libs')
The reason this works is the guy who has created this project has excluded the xmlbeans.jar from basic poi.jar with which android build has problem. Credit goes to the guy andruhon.
This workaround worked for me hence posting as answer
The poi library has dependancy clashes with multidex apk build. To fix these clashes:
- Remove gradle reference to the dependancy or jar [as bellow].
- Add this jar without clashing dependancies to /lib
Add the following line to module gradle:
// implementation 'org.apache.poi:poi-ooxml:3.17'
implementation files('libs/poishadow-all.jar')
You can also right click the jar and choose add as library which will do this automatically
The jar was built from This Github repository
来源:https://stackoverflow.com/questions/38201667/android-apache-poi-duplicate-entry-org-apache-xmlbeans-xml-stream-location-cl