centic9 / poi-on-android

A sample project that shows how Apache POI can be used in an Android application
Apache License 2.0
357 stars 89 forks source link

java.lang.ExceptionInInitializerError #46

Closed vik17ag closed 2 years ago

vik17ag commented 6 years ago

Hi

While importing an .xls or .xlsx file into my project, I get this error. My code is as follows - Workbook workbook; InputStream fis = mContext.get().getContentResolver().openInputStream(uri); workbook = WorkbookFactory.create(fis);

Logs -

Caused by: java.lang.ExceptionInInitializerError at org.apache.poi.d.b.dc.a(SourceFile:489) at org.apache.poi.d.c.ay.<init>(SourceFile:356) at org.apache.poi.ss.usermodel.WorkbookFactory.create(SourceFile:101) at org.apache.poi.ss.usermodel.WorkbookFactory.create(SourceFile:186) at org.apache.poi.ss.usermodel.WorkbookFactory.create(SourceFile:148) at vivekagarwal.playwithdb.p.a(SourceFile:88) at vivekagarwal.playwithdb.p.a(SourceFile:73) at vivekagarwal.playwithdb.p.doInBackground(SourceFile:38) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)  at java.lang.Thread.run(Thread.java:764)  Caused by: org.apache.poi.i.ac: Unable to determine record types at org.apache.poi.d.b.dc.a(SourceFile:446) at org.apache.poi.d.b.dc.<clinit>(SourceFile:292) at org.apache.poi.d.b.dc.a(SourceFile:489)  at org.apache.poi.d.c.ay.<init>(SourceFile:356)  at org.apache.poi.ss.usermodel.WorkbookFactory.create(SourceFile:101)  at org.apache.poi.ss.usermodel.WorkbookFactory.create(SourceFile:186)  at org.apache.poi.ss.usermodel.WorkbookFactory.create(SourceFile:148)  at vivekagarwal.playwithdb.p.a(SourceFile:88)  at vivekagarwal.playwithdb.p.a(SourceFile:73)  at vivekagarwal.playwithdb.p.doInBackground(SourceFile:38)  at android.os.AsyncTask$2.call(AsyncTask.java:333)  at java.util.concurrent.FutureTask.run(FutureTask.java:266)  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)  at java.lang.Thread.run(Thread.java:764) 

This works perfectly fine in Debug build i.e. without proguard. I think I need to mention -keep for some class , but cant figure out which 1.

I have added following lines in proguard so that these classes are not obfuscated by proguard and stays intact.

`-dontwarn org.apache. -dontwarn org.openxmlformats.schemas. -dontwarn org.etsi. -dontwarn org.w3. -dontwarn com.microsoft.schemas. -dontwarn com.graphbuilder. -dontnote org.apache. -dontnote org.openxmlformats.schemas. -dontnote org.etsi. -dontnote org.w3. -dontnote com.microsoft.schemas. -dontnote com.graphbuilder.

-keeppackagenames org.apache.poi.ss.formula.function

-keep class com.fasterxml.aalto.stax.InputFactoryImpl -keep class com.fasterxml.aalto.stax.OutputFactoryImpl -keep class com.fasterxml.aalto.stax.EventFactoryImpl

-keep class schemaorg_apache_xmlbeans.system.sF1327CCA741569E70F9CA8C9AF9B44B2.TypeSystemHolder { public final static *** typeSystem; }

-keep class org.apache.xmlbeans.impl. { *; } -keep class org.openxmlformats.schemas.spreadsheetml.x2006.main.* { ;} -keep class org.apache.poi.ss. { *;}

-keep class org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl.CTPropertiesImpl { ; } -keep class org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl.PropertiesDocumentImpl { ; } -keep class org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl.CTPropertiesImpl { ; } -keep class org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl.PropertiesDocumentImpl { ; } -keep class org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.impl.CTDrawingImpl { ; } -keep class org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.impl.CTMarkerImpl { ; } -keep class com.microsoft.schemas.office.office.impl.CTIdMapImpl { ; } -keep class com.microsoft.schemas.office.office.impl.CTShapeLayoutImpl { ; } -keep class com.microsoft.schemas.vml.impl.CTShadowImpl { ; } -keep class com.microsoft.schemas.vml.impl.CTFillImpl { ; } -keep class com.microsoft.schemas.vml.impl.CTPathImpl { ; } -keep class com.microsoft.schemas.vml.impl.CTShapeImpl { ; } -keep class com.microsoft.schemas.vml.impl.CTShapetypeImpl { ; } -keep class com.microsoft.schemas.vml.impl.CTStrokeImpl { ; } -keep class com.microsoft.schemas.vml.impl.CTTextboxImpl { ; } -keep class com.microsoft.schemas.office.excel.impl.CTClientDataImpl { ; } -keep class com.microsoft.schemas.office.excel.impl.STTrueFalseBlankImpl { *; }` Can you help?

vik17ag commented 6 years ago

I added below lines in proguard to resolve the error. Although, it increased the apk size by 500KB.

-keep public class org.apache.poi.** {*;} I would appreciate if someone can post a better solution. Thanks!

centic9 commented 2 years ago

I believe there were some changes to the project over time which should make this work now, there are similar steps performed and no such crash is visible.

Thus I am closing this for now, please report new issues for things that you encounter with the latest version of the project.