在Android中使用poi-3.12-android-a.jar,poi-ooxml-schemas-3.12-20150511-a.jar读写excel,
出现下面的异常:
2021-04-09 14:31:38.563 14429-14532/? W/System.err: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:6)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:10)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:2)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:18)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at com.zhining.sort.g.i.g.a(ExcelUtil.java:10)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at com.zhining.sort.ui.activity.DataImportExportActivity.a(DataImportExportActivity.java:94)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at com.zhining.sort.ui.activity.f5.a(Unknown Source:4)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.t0.e.b.c0.d(FlowableCreate.java:8)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.k.a(Flowable.java:449)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.k.subscribe(Flowable.java:2)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.t0.e.b.r4$a.a(FlowableZip.java:3)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.t0.e.b.r4.d(FlowableZip.java:11)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.k.a(Flowable.java:449)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.k.subscribe(Flowable.java:2)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.t0.e.b.w.d(FlowableConcatMap.java:2)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.k.a(Flowable.java:449)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.k.subscribe(Flowable.java:2)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.t0.e.b.w.d(FlowableConcatMap.java:2)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.k.a(Flowable.java:449)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.k.subscribe(Flowable.java:2)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.t0.e.b.q3$a.run(FlowableSubscribeOn.java:4)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.t0.g.n.run(ScheduledRunnable.java:2)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at f.a.t0.g.n.call(ScheduledRunnable.java:1)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2021-04-09 14:31:38.563 14429-14532/? W/System.err: at java.lang.Thread.run(Thread.java:764)
解决方法是,在proguard-rules.pro文件中排除上面两个jar中所有包的混淆,如下:
-keep class com.bea.xml.stream.** { *;}
-keep class com.wutka.dtd.** { *;}
-keep class org.** { *;}
-keep class aavax.xml.** { *;}
-keep class com.microsoft.schemas.office.x2006.** { *; }
-keep class schemaorg_apache_xmlbeans.** { *; }
-keep class schemasMicrosoftComOfficeExcel.** { *; }
-keep class schemasMicrosoftComOfficeOffice.** { *; }
-keep class schemasMicrosoftComVml.** { *; }
-keep class repackage.** { *; }
-keep class schemaorg_apache_xmlbeans.** { *; }