For getting Apache POI to work on Android, I need to get Stack to work on Android. Following this question:Using JAXB with Google Android and @Sean Barbeau's answer.
I successfully converted all the jar's to android compatible ones including the Apache POI library but it still gives me this run time error:
06-22 01:06:52.461 14865-14865/com.quizwiz.sharmakritya.poi E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.quizwiz.sharmakritya.poi, PID: 14865
edu.usf.cutr.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
at edu.usf.cutr.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at edu.usf.cutr.javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:162)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:142)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:37)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:87)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:273)
at org.apache.poi.xslf.usermodel.XMLSlideShow.empty(XMLSlideShow.java:103)
at org.apache.poi.xslf.usermodel.XMLSlideShow.<init>(XMLSlideShow.java:75)
at com.quizwiz.sharmakritya.poi.PPT.onCreate(PPT.java:16)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
The crux of the whole error is android is missing the package com.bea.xml.stream
. How do I resolve this ?
I tried resolving this on my own by downloading an external jar from here. But that gave me strange errors:
06-22 01:10:42.906 20374-20374/com.quizwiz.sharmakritya.poi E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.quizwiz.sharmakritya.poi, PID: 20374
java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.RuntimeException: Multi dex installation failed (Field dexElementsSuppressedExceptions not found in class dalvik.system.PathClassLoader).
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703)
at android.app.ActivityThread.access$1600(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Multi dex installation failed (Field dexElementsSuppressedExceptions not found in class dalvik.system.PathClassLoader).
at android.support.multidex.MultiDex.install(MultiDex.java:178)
at android.support.multidex.MultiDexApplication.attachBaseContext(MultiDexApplication.java:39)
at android.app.Application.attach(Application.java:201)
at android.app.Instrumentation.newApplication(Instrumentation.java:997)
at android.app.Instrumentation.newApplication(Instrumentation.java:981)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
????????????at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703)
????????????at android.app.ActivityThread.access$1600(ActivityThread.java:175)
????????????at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
????????????at android.os.Handler.dispatchMessage(Handler.java:102)
????????????at android.os.Looper.loop(Looper.java:146)
????????????at android.app.ActivityThread.main(ActivityThread.java:5602)
????????????at java.lang.reflect.Method.invokeNative(Native Method)
????????????at java.lang.reflect.Method.invoke(Method.java:515)
????????????at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
????????????at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
????????????at dalvik.system.NativeStart.main(Native Method)
Note: removing the com.bea.stax.impl_1.2.0.jar from Gradle Dependencies gets me back to the first error.
Please help me find a way to use the package com.bea.xml.stream on android.
UPDATE
The dependencies before your answer in gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions{
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
}
defaultConfig {
applicationId "com.quizwiz.sharmakritya.poi"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:multidex:1.0.0'
compile files('libs/stax-api-android-1.0-2.jar')
compile files('libs/stax2-api-android-3.1.1.jar')
//compile files('libs/com.bea.stax.impl_1.2.0.jar')
compile files('libs/poi-3.12-20150511.jar')
compile files('libs/poi-ooxml-3.12-20150511.jar')
compile files('libs/poi-ooxml-schemas-3.12-20150511.jar'){
exclude group: 'stax', module: 'stax-api'
}
compile files('libs/xmlbeans-2.6.0.jar')
compile files('libs/stax-1.2.0_rc2-dev.jar')
}
UPDATE #2
The error while compilation I get:
Error:duplicate files during packaging of APK C:UserssharmakrityaAndroidStudioProjectsPOIappuildoutputsapkapp-debug-unaligned.apk
Path in archive: META-INF/services/javax.xml.stream.XMLInputFactory
Origin 1: C:UserssharmakrityaAndroidStudioProjectsPOIappuildintermediatesjavaResourcesdebugMETA-INFservicesjavax.xml.stream.XMLInputFactory
Origin 2: C:Userssharmakritya.gradlecachesmodules-2files-2.1edu.usf.cutr.android.xmlaalto-xml-android.9.8f4e7339b028f92638b36ab9ac3cc3314a860d1aalto-xml-android-0.9.8.jar
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'META-INF/services/javax.xml.stream.XMLInputFactory'
}
}
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/services/javax.xml.stream.XMLInputFactory
File 1: C:UserssharmakrityaAndroidStudioProjectsPOIappuildintermediatesjavaResourcesdebugMETA-INFservicesjavax.xml.stream.XMLInputFactory
File 2: C:UserssharmakrityaAndroidStudioProjectsPOIappuildintermediatesjavaResourcesdebugMETA-INFservicesjavax.xml.stream.XMLInputFactory
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…