Java NoClassDefFoundError with DexGuard and spongycastle

2.7k views Asked by At

I'm trying to get DexGuard running on a project I'm working on. I already have ProGuard running successfully with proguard-rules.pro. After running a DexGuard release built the app crashes with

FATAL EXCEPTION: main
Process: com.project.fr, PID: 7937
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/spongycastle/jce/provider/BouncyCastleProvider;
    at com.project.CustomApplication.<clinit>(:44)
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at java.lang.Class.newInstance(Class.java:1572)
    at android.app.Instrumentation.newApplication(Instrumentation.java:994)
    at android.app.Instrumentation.newApplication(Instrumentation.java:979)
    at android.app.LoadedApk.makeApplication(LoadedApk.java:558)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4491)
    at android.app.ActivityThread.access$1500(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.spongycastle.jce.provider.BouncyCastleProvider" on path: DexPathList[[zip file "/data/app/com.project.fr-1/base.apk"],nativeLibraryDirectories=[/data/app/com.project.fr-1/lib/arm, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 16 more
    Suppressed: java.lang.ClassNotFoundException: org.spongycastle.jce.provider.BouncyCastleProvider
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 17 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

When a I build the app with proguard and the same proguard-rules.pro it runs fine.

In the rules.pro I have this option enabled.

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

Which according to post Using Spongycastle with Proguard should be te fix.

The whole proguard-rules.pro can be found here link to gist

1

There are 1 answers

1
Eric Lafortune On BEST ANSWER

For completeness' sake: we've worked out by e-mail that the problem was caused by the option "minifyEnabled true" in build.gradle, which is incompatible with the DexGuard plugin. DexGuard of course already provides shrinking, optimization, and obfuscation.

(I am the developer of ProGuard and DexGuard)