Using Spongycastle with Proguard

2019-05-11 16:18发布

问题:

I've been strugling with proguard to make Spongycastle work. Most of the time, the problem comes when I'm exporting a signed APK, either I've got error, or the app will just crash before starting.

So, I've managed to gather informations to get a working proguard configuration :

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-repackageclasses ''
-allowaccessmodification
-keepattributes *Annotation*

-optimizations !code/simplification/arithmetic

-libraryjars C:\Program Files\Java\jre7\lib\rt.jar
-libraryjars libs\sc-light-jdk15on-1.47.0.2.jar
-libraryjars libs\scprov-jdk15on-1.47.0.2.jar

-injars libs

-outjars bin/classes-processed.jar

-dontwarn javax.naming.**
-dontwarn android.support.**


####
-keep class org.**  { *; }

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

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

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

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

I'm running ADT Version: 22.0.0.v201305140200--675183 The test phone is under Android 2.3.5

The part that borrows me is the "-keep class org.** { *; }" .... Am I doing it right ? I've tried "-keep class org.spongycastle.** { *; }", but the app just crash before startup...

Thanks !

回答1:

We added

-keep class org.spongycastle.**
-dontwarn org.spongycastle.jce.provider.X509LDAPCertStoreSpi
-dontwarn org.spongycastle.x509.util.LDAPStoreHelper

But we now run into the problem that we hit the DEX method limit of 2^16 with that lib. We only need it for the MD5 and SHA-1 algorithms as some phones don't ship those.