Android app crashes when minifyEnabled is true

Tags: , ,



I am using a multi-module app and the app crashes when minifyEnabled true in the installed module’s build.gradle.

Following is the deobfuscated stacktrace I retrieved from play console.

 FATAL EXCEPTION: ControllerMessenger
Process: com.packagename, PID: 16978
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
    at com.packagename.login.Utils.AuthenticationActions.saveCredentials(AuthenticationActions.java)
    at com.packagename.login.LoginActivity$1$1.onCompleted(LoginActivity.java)
    at com.packagename.login.LoginActivity$1$1.onCompleted(LoginActivity.java)
    at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java)
    at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java)
    at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java)
    at com.koushikdutta.ion.IonRequestBuilder$EmitterTransform$1.onCompleted(IonRequestBuilder.java)
    at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java)
    at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java)
    at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java)
    at com.koushikdutta.ion.IonRequestBuilder$1.run(IonRequestBuilder.java)
    at com.koushikdutta.async.AsyncServer$RunnableWrapper.run(AsyncServer.java)
    at android.os.Handler.handleCallback(Handler.java:746)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at androidx.test.espresso.base.Interrogator.a(Interrogator.java:19)
    at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:166)
    at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:158)
    at androidx.test.espresso.base.UiControllerImpl.a(UiControllerImpl.java:34)
    at androidx.test.espresso.action.MotionEvents.a(MotionEvents.java:77)
    at androidx.test.espresso.action.MotionEvents.a(MotionEvents.java:52)
    at androidx.test.espresso.action.Tap.c(Tap.java:8)
    at androidx.test.espresso.action.Tap.b(Tap.java:18)
    at androidx.test.espresso.action.Tap$1.a(Tap.java:3)
    at androidx.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:22)
    at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:9)
    at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:79)
    at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:96)
    at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:3)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.Handler.handleCallback(Handler.java:746)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5459)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

I am unable to understand what does this code correspond to 'java.lang.Object java.util.List.get(int)'

I am using multiple external libraries, one of which is ion koush.

I have tried adding this to ever proguard-rules.pro file in my project -keep class com.koushikdutta.** { *;}. But this didn’t yield any success.

Answer

This happens when your app transform json to POJOs and you have minify enable. Minify change those POJOs making the transformation impossible (it will compile, but all your POJOs propierties will be null).

Keep those POJOs adding -keep class com.packagename.<path to pojos> {*; } to your proguard-rules file.



Source: stackoverflow