1

I'm using retrofit with okhttp and migrated to AndroidX, When I make a signed app that obfuscated with proguard it crashes and gives an error,but in debug mode when proguard is not enabled it's working good. and I disabled proguard just for testing and made a signed APK it's working this way too. so I'm sure the crash is caused by Proguard. And I did some search on google they all say that I have to add proguard rules for both OKHTTP and Retrofit I did add them too but it still crashes. The error is logged from Crashlytics because I didn't enable proguard in debug mode:

PagedStorage.java line 118
androidx.paging.PagedStorage.init

Fatal Exception: java.lang.NullPointerException
Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
androidx.paging.PagedStorage.init (PagedStorage.java:118)
androidx.paging.PagedStorage.init (PagedStorage.java:131)
androidx.paging.ContiguousPagedList$1.onPageResult (ContiguousPagedList.java:81)
androidx.paging.DataSource$LoadCallbackHelper$1.run (DataSource.java:324)
android.os.Handler.handleCallback (Handler.java:790)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loop (Looper.java:164)
android.app.ActivityThread.main (ActivityThread.java:7000)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:441)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)

Thread-20
java.lang.Object.wait (Object.java)
java.lang.Thread.parkFor$ (Thread.java:2137)
sun.misc.Unsafe.park (Unsafe.java:358)
java.util.concurrent.locks.LockSupport.park (LockSupport.java:190)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await (AbstractQueuedSynchronizer.java:2059)
java.util.concurrent.PriorityBlockingQueue.take (PriorityBlockingQueue.java:548)
com.android.volley.NetworkDispatcher.processRequest (NetworkDispatcher.java:104)
com.android.volley.NetworkDispatcher.run (Network

Dispatcher.java:87)

And that's my Proguard rules:

-dontwarn org.conscrypt.OpenSSLProvider
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception

-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

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

# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.-KotlinExtensions

# 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.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

# 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 dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform

-keep class com.google.android.material.** { *; }

-dontwarn com.google.android.material.**
-dontnote com.google.android.material.**

this part added after the crash but it's still useless

-dontwarn androidx.**
-keep class androidx.** { *; }
-keep interface androidx.** { *; }

-keep class androidx.paging.PagedStorage.init
user2682025
  • 656
  • 2
  • 13
  • 39
  • Same problem to me but no luck found. I'm also sure proguard is the problems. almost crash of my app is this problem. even I've tried this: ``` -keep class androidx.paging.** { *; } -keepclasseswithmembers class * { public static FirebaseAuth getInstance (); } -keep class com.google.firebase.** { *; } -keep class com.firebase.** { *; } – Slim_user71169 Jan 09 '19 at 04:09
  • After more than a month of research an testing I found out that Proguard was the issue it was obfuscating my models (pojo) classes and making wrong routes so the app could not reach these classes any more and androidx.paging had null paramters. so I did --keep these classes and the problem solved. – user2682025 Jan 09 '19 at 08:49
  • i am getting this even in debug app .. Any hint for me ? – SimpleCoder May 25 '19 at 15:01
  • @SimpleCoder is there anyway that you enabled Proguard in debug mode? – user2682025 May 25 '19 at 21:48
  • @user2682025 Were you able to slove this issue ? – Zoo Zoo May 06 '20 at 10:18

1 Answers1

0

I can solved this problem by -keep myModelclass(or be pakages) in progaurd, but i have not know awarness it's good or not.

-keep class com.appname.dashboard.model**{*; }

Umesh Yadav
  • 1,042
  • 9
  • 17