Android + Proguard + Apache POI

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Android + Proguard + Apache POI

Delphian
Someone was able to get the Apache POI library to work after obfuscation. I read a lot of information, tried different methods, but still get the error:

a.a.b.a: Provider com.bea.xml.stream.EventFactory not found
org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(Unknown Source)
at org.apache.poi.openxml4j.opc.OPCPackage.init(Unknown Source)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(Unknown Source)
at org.apache.poi.openxml4j.opc.Package.<init>(Unknown Source)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(Unknown Source)
at org.apache.poi.openxml4j.opc.OPCPackage.create(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.newPackage(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)


I added the jars files into libs folder: poi-ooxml-schemas-3.12-20150511-a.jar and poi-3.12-android-a.jar.

My proguard-rules.pro:

-dontwarn org.apache.**
-dontwarn org.openxmlformats.**
-dontwarn schemasMicrosoftComVml.**
-dontwarn org.w3.x2000.**
-dontwarn org.etsi.uri.**
-dontwarn com.microsoft.schemas.**
-dontwarn schemasMicrosoftComOfficeOffice.**
-dontwarn schemasMicrosoftComOfficeExcel.**
-dontwarn com.google.common.**

-keeppackagenames org.jsoup.nodes
-keepattributes *Annotation*, EnclosingMethod,Signature, JavascriptInterface
-keep class com.google.common.**

#Parcel
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
-keep class org.parceler.Parceler$$Parcels

#Apache poi
-keep public class org.apache.poi.** {*;}
-keep class com.fasterxml.aalto.** {*;}
-keep class org.apache.xmlbeans.** {*;}
-keep class org.openxmlformats.schemas.** {*;}
-keep class com.microsoft.schemas.** {*;}

#BUTTERKNIFE
-keep public class * implements butterknife.internal.ViewBinder { public <init>(); }

# Prevent obfuscation of types which use ButterKnife annotations since the simple name
# is used to reflectively look up the generated ViewBinder.
-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Android + Proguard + Apache POI

Dominik Stadler
Hi,

I am not an expert in proguard, so cannot give help in that regard, but
some time ago I built a project that allows me to do some stuff with POI on
Android, see https://github.com/centic9/poi-on-android/ for details. Maybe
some of the build-files there let you see your problem.

Also the error does not necessarily indicate a problem with obfuscation, it
seems the com.bea.xml.stream package is tried when no other XML Parser is
found and thus it might just be that you do not have an XML Parser
available. In poi-on-android I use a separate implementation aalto-xml
<https://github.com/FasterXML/aalto-xml> to account for that...

Dominik.

On Sat, Jun 3, 2017 at 2:38 PM, Delphian <[hidden email]> wrote:

> Someone was able to get the Apache POI library to work after obfuscation. I
> read a lot of information, tried different methods, but still get the
> error:
>
> *a.a.b.a: Provider com.bea.xml.stream.EventFactory not found
> org.apache.poi.openxml4j.opc.internal.marshallers.
> PackagePropertiesMarshaller.<clinit>(Unknown
> Source)
> at org.apache.poi.openxml4j.opc.OPCPackage.init(Unknown Source)
> at org.apache.poi.openxml4j.opc.OPCPackage.<init>(Unknown Source)
> at org.apache.poi.openxml4j.opc.Package.<init>(Unknown Source)
> at org.apache.poi.openxml4j.opc.ZipPackage.<init>(Unknown Source)
> at org.apache.poi.openxml4j.opc.OPCPackage.create(Unknown Source)
> at org.apache.poi.xssf.usermodel.XSSFWorkbook.newPackage(Unknown Source)
> at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
> at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
> at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
> at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)*
>
> I added the jars files into libs folder:
> poi-ooxml-schemas-3.12-20150511-a.jar and poi-3.12-android-a.jar.
>
> My proguard-rules.pro:
>
> -dontwarn org.apache.**
> -dontwarn org.openxmlformats.**
> -dontwarn schemasMicrosoftComVml.**
> -dontwarn org.w3.x2000.**
> -dontwarn org.etsi.uri.**
> -dontwarn com.microsoft.schemas.**
> -dontwarn schemasMicrosoftComOfficeOffice.**
> -dontwarn schemasMicrosoftComOfficeExcel.**
> -dontwarn com.google.common.**
>
> -keeppackagenames org.jsoup.nodes
> -keepattributes *Annotation*, EnclosingMethod,Signature,
> JavascriptInterface
> -keep class com.google.common.**
>
> #Parcel
> -keep class * implements android.os.Parcelable {
>   public static final android.os.Parcelable$Creator *;
> }
> -keep class org.parceler.Parceler$$Parcels
>
> #Apache poi
> -keep public class org.apache.poi.** {*;}
> -keep class com.fasterxml.aalto.** {*;}
> -keep class org.apache.xmlbeans.** {*;}
> -keep class org.openxmlformats.schemas.** {*;}
> -keep class com.microsoft.schemas.** {*;}
>
> #BUTTERKNIFE
> -keep public class * implements butterknife.internal.ViewBinder { public
> <init>(); }
>
> # Prevent obfuscation of types which use ButterKnife annotations since the
> simple name
> # is used to reflectively look up the generated ViewBinder.
> -keep class butterknife.*
> -keepclasseswithmembernames class * { @butterknife.* <methods>; }
> -keepclasseswithmembernames class * { @butterknife.* <fields>; }
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.
> nabble.com/Android-Proguard-Apache-POI-tp5727688.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Android + Proguard + Apache POI

Delphian
Dominik, thank you. I created an empty project and added poishadow-all.jar, but when I start excel operation (without proguard) I caught the error:

 org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
                                                                             at org.apache.poi.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
                                                                             at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
                                                                             at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
                                                                             at org.apache.poi.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:161)
                                                                             at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
                                                                             at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:72)
                                                                             at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:394)
                                                                             at org.apache.poi.xssf.usermodel.XSSFWorkbook.newPackage(XSSFWorkbook.java:475)
                                                                             at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:243)
                                                                             at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:235)
                                                                             at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:240)
                                                                             at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:210)
                                                                             at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:185)
                                                                             at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:271)
                                                                             at com.che.apachepoicentic.ExcelInteraction.writeSheet(ExcelInteraction.java:52)
                                                                             at com.che.apachepoicentic.ExcelInteraction.onHandleIntent(ExcelInteraction.java:32)
                                                                             at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:148)
                                                                             at android.os.HandlerThread.run(HandlerThread.java:61)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Android + Proguard + Apache POI

Dominik Stadler
Hi,

I found out what the difference in my test-application is. I am setting a
few system properties during startup so that the XML parser is found. It
seems Android handles this somehow differently than normal Java.

System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory",
"com.fasterxml.aalto.stax.InputFactoryImpl");
System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory",
"com.fasterxml.aalto.stax.OutputFactoryImpl");
System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory",
"com.fasterxml.aalto.stax.EventFactoryImpl");

See the updated README at https://github.com/centic9/poi-on-android/ for
more details.

Thanks... Dominik.

On Mon, Jun 12, 2017 at 4:38 PM, Delphian <[hidden email]> wrote:

> Dominik, thank you. I created an empty project and added poishadow-all.jar,
> but when I start excel operation (without proguard) I caught the error:
>
> / org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider
> com.bea.xml.stream.EventFactory not found
>
> at
> org.apache.poi.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.
> java:72)
>
> at
> org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
>
> at org.apache.poi.javax.xml.stream.FactoryFinder.find(
> FactoryFinder.java:92)
>
> at
> org.apache.poi.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:161)
>
> at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
>
> at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:72)
>
> at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:394)
>
> at
> org.apache.poi.xssf.usermodel.XSSFWorkbook.newPackage(
> XSSFWorkbook.java:475)
>
> at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(
> XSSFWorkbook.java:243)
>
> at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(
> XSSFWorkbook.java:235)
>
> at
> org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:240)
>
> at
> org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:210)
>
> at
> org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:185)
>
> at
> org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:271)
>
> at
> com.che.apachepoicentic.ExcelInteraction.writeSheet(
> ExcelInteraction.java:52)
>
> at
> com.che.apachepoicentic.ExcelInteraction.onHandleIntent(
> ExcelInteraction.java:32)
>
> at
> android.app.IntentService$ServiceHandler.handleMessage(
> IntentService.java:66)
>
> at android.os.Handler.dispatchMessage(Handler.java:102)
>
> at android.os.Looper.loop(Looper.java:148)
>
> at android.os.HandlerThread.run(HandlerThread.java:61)/
>
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.
> nabble.com/Android-Proguard-Apache-POI-tp5727688p5727744.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Loading...