Yash Joshi
Yash Joshi

Reputation: 627

Android - App with obfuscated AAR library is crashing when minifyEnabled true causes java.lang.ExceptionInInitializerError

I have an android app that uses CSRMesh Library as an AAR module. The AAR itself is obfuscated. My app works fine when minifyEnabled is false in build.gradle but when I set it to true the app is crashing.

The following code is from a custom MeshLibraryManager class for making API calls to the library.

private void enableBluetooth() {
    try {
        mCurrentChannel = MeshChannel.BLUETOOTH;
        isChannelReady = false;
        mBtBearer = new BluetoothBearer(this, mContext.get());
        if (mService != null) {
            mService.setBearer(mBtBearer);  // crash occurs in this line
            mService.setBluetoothBearerEnabled(mBtBearer);
        }
        EventBus.getDefault().post(new MeshSystemEvent(MeshSystemEvent.SystemEvent.CHANNEL_NOT_READY));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

In this code block, mService is an instance of the MeshService class from the library. I have added a comment in the line where the app crashes. If I comment out that line and the line below it the app doesn't crash but then I'm not able to perform the required Bluetooth operations.

This is the complete stack trace of the crash:

2021-05-14 16:21:48.994 27372-27372/com.example.myApp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myApp, PID: 27372
    java.lang.ExceptionInInitializerError
        at com.csr.internal.mesh_le.g0.a(SourceFile:70)
        at com.csr.internal.mesh_le.f.l(SourceFile:269)
        at com.csr.csrmesh2.MeshService.y(SourceFile:309)
        at com.example.scanner.api.MeshLibraryManager.v(SourceFile:336)
        at com.example.scanner.api.MeshLibraryManager.o(SourceFile:59)
        at com.example.scanner.api.MeshLibraryManager$b.onServiceConnected(SourceFile:595)
        at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1738)
        at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1770)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6820)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:922)
    

I have tried adding proguard rules for the required classes whichever I could figure from code and stack trace but nothing works.

Please suggest how can I fix this.

Upvotes: 1

Views: 1238

Answers (1)

Shailendra Madda
Shailendra Madda

Reputation: 21531

You must ensure that the following line will be there in your proguard rules. This will tell your application to ensure that the SpongyCastle encryption libraries can be used.

-keep class org.spongycastle.jcajce.provider.asymmetric.** { *; }

Upvotes: 1

Related Questions