Search code examples
javaandroidandroid-gradle-pluginapache-poiandroid-multidex

Android : Apache POI duplicate entry: org/apache/xmlbeans/xml/stream/Location.class error


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.


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.