'ProGuard settings for Apache POI

I'm building an application that uses the Apache POI library. When I debug the app (compile it without running Proguard) everything is working great, however after exporting the APK, when I run the application and open an Excel file I get the following exception:

RuntimeException - Caused by: java.lang.ExceptionInInitializerError at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:301)

Here is my proguard settings file:

-injars      bin/classes
-injars      libs/android-support-v13.jar
-outjars     bin/classes-processed.jar
-libraryjars /usr/bin/adt/sdk/platforms/android-19/android.jar
-libraryjars libs/poi-3.10.1.jar

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-dontwarn org.apache.poi.**
-dontwarn com.google.**
-dontwarn android.support.**

-keep public class * extends android.app.Activity
-keep public class * extends android.support.v4.app.FragmentActivity
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver

-keep class com.android.vending.billing.**

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

What is the correct configuration for Apache POI in Proguard? I use POI to only read the old (Excel 97) format so I don't need all the other jars.



Solution 1:[1]

I ended up adding the following line:

-keep public class org.apache.poi.** {*;}

That seems to fix the problem

Solution 2:[2]

for read/write excel [xls|xlsx] files. I use below in proguard

# poi
# https://github.com/centic9/poi-on-android/blob/master/poitest/proguard-rules.pro
    -keeppackagenames aavax.**
-keeppackagenames org.apache.poi.**
-keeppackagenames org.apache.poi.ss.formula.function
-keeppackagenames org.openxmlformats.**
-keeppackagenames org.openxmlformats.schemas.**

-keep class aavax.** {*;}
-keep class org.apache.poi.** {*;}
-keep class org.apache.xmlbeans.** {*;}
-keep class com.fasterxml.** {*;}
-keep class com.microsoft.schemas.** {*;}

-keep class org.openxmlformats.** {*;}
-keep class org.openxmlformats.schemas.** {*;}
-keep class schemaorg_apache_xmlbeans.** {*;}
-keep class schemasMicrosoftComVml.** {*;}
-keep class schemasMicrosoftComOfficeExcel.** {*;}
-keep class schemasMicrosoftComOfficeOffice.** {*;}

-keepclasseswithmembers class aavax.** {*;}
-keepclasseswithmembers class org.apache.poi.** {*;}
-keepclasseswithmembers class org.apache.xmlbeans.** {*;}
-keepclasseswithmembers class com.fasterxml.** {*;}
-keepclasseswithmembers class com.microsoft.schemas.** {*;}

-keepclasseswithmembers class org.openxmlformats.** {*;}
-keepclasseswithmembers class org.openxmlformats.schemas.** {*;}
-keepclasseswithmembers class schemaorg_apache_xmlbeans.** {*;}
-keepclasseswithmembers class schemasMicrosoftComVml.** {*;}
-keepclasseswithmembers class schemasMicrosoftComOfficeExcel.** {*;}
-keepclasseswithmembers class schemasMicrosoftComOfficeOffice.** {*;}

-keep class org.w3c.** {*;}
-keep class org.dom4j.** {*;}
-keep class org.etsi.** {*;}
-keep class com.graphbuilder.** {*;}
-dontwarn org.etsi.**
-dontnote com.microsoft.schemas.**
-dontnote com.graphbuilder.**
-dontwarn org.openxmlformats.**
-dontwarn org.w3c.**
-dontwarn org.dom4j.**
-dontwarn schemasMicrosoftComVml.**
-dontwarn schemasMicrosoftComOfficeExcel.**
-dontwarn schemasMicrosoftComOfficeOffice.**
-dontwarn schemasMicrosoftComOfficeWord.**

Solution 3:[3]

Adding next classes will be enough:

-keep class org.apache.poi.** {*;}
-keep class org.apache.xmlbeans.** {*;}
-keep class com.fasterxml.** {*;}
-keep class com.microsoft.schemas.** {*;}
-keep class org.openxmlformats.** {*;}
-keep class org.openxmlformats.schemas.** {*;}
-keep class schemaorg_apache_xmlbeans.** {*;}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mittelmania
Solution 2
Solution 3 kaiv