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

陌路散爱 提交于 2019-12-02 02:29:56

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:

  1. Remove gradle reference to the dependancy or jar [as bellow].
  2. Add this jar without clashing dependancies to /lib
  3. Add the following line to module gradle:

    //    implementation 'org.apache.poi:poi-ooxml:3.17'
    

    implementation files('libs/poishadow-all.jar')

  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!