Search code examples
kotlinsignalrokhttpproguardandroid-r8

Android Studio, okhttp: Building a Release version of app causes NullPointerException: getConnectionId(...)


Building a release version of app and running it, causes following error: When building a debug version, the app works as expected.

FATAL EXCEPTION: e9.s Dispatcher
Process: com.example.premi, PID: 18240
java.lang.NullPointerException: getConnectionId(...) must not be null
at y4.c.a(SourceFile:392)
at y4.i$b.d(SourceFile:87)
at i9.e$a.run(SourceFile:43)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)

I am using Okhttp client that throws Callback failure with code 400 just before Fatal exception

I tried adding following rules to proguard but with not luck (see below), any guesses what can it be?

# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
-adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt and other security providers are available.
-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**

EDIT: error traced in mapping.txt, found out signalR was the problem, added following lines of code in proguard-rules.pro

-keep class com.microsoft.signalr.** { *; }

-keep interface com.microsoft.signalr.** { *; }


Solution

  • I have traced error in mapping.txt, and found out that the SignalR was throwing error, so I went to a proguard-rules.pro and added following lines of code and afterwards, it worked.

    -keep class com.microsoft.signalr.** { ; } 
    -keep interface com.microsoft.signalr.* { *; }
    

    Hope this helps