unsplash / unsplash-photopicker-android

📱An Android photo picker to search and download photos from Unsplash.
MIT License
336 stars 62 forks source link

Crash in release mode caused by missing proguard rule #9

Open ChrisJan00 opened 3 years ago

ChrisJan00 commented 3 years ago

Describe the bug A project using this component crashes in Release mode when launching the picker. The problem does not happen in Debug mode.

To Reproduce Steps to reproduce the behavior:

  1. Add photopicker to your app following the instructions from the README file
  2. Launch a release build of your app
  3. Navigate to the picker

Expected behavior The picker activity is open and the user can navigate through a stacked grid view of photos from the unsplash website.

Observed behavior The app crashes.

Additional context Stacktrace from Logcat:

08-27 10:07:47.849  8556  8556 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'char java.lang.String.charAt(int)' on a null object reference
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.graphics.Color.parseColor(Color.java:1384)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at d.j.a.a.e.c.p(UnsplashPhotoAdapter.kt:19)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.RecyclerView$g.q(RecyclerView.java:1)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.RecyclerView$v.l(RecyclerView.java:166)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.RecyclerView$v.e(RecyclerView.java:1)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.StaggeredGridLayoutManager.k1(StaggeredGridLayoutManager.java:14)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.StaggeredGridLayoutManager.x1(StaggeredGridLayoutManager.java:140)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.StaggeredGridLayoutManager.A0(StaggeredGridLayoutManager.java:1)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:14)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:9)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:20)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at androidx.recyclerview.widget.RecyclerView$a.run(RecyclerView.java:6)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.view.Choreographer.doCallbacks(Choreographer.java:790)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.view.Choreographer.doFrame(Choreographer.java:721)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:883)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:100)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:214)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7356)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
08-27 10:07:47.849  8556  8556 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Solution I fixed the issue by adding the following line to my project's proguard-rules.pro file:

-keep class com.unsplash.pickerandroid.photopicker.data.** { *; }

The problem is fixed this way on my side. I thought I'd be nice to report it, for other users. Imho this or an equivalent addition to the proguard rules should be mentioned in the README file. Or, if that's reasonable, directly applied to the relevant files in this repository.

quocthinh212 commented 2 years ago

Another way -keep class io.reactivex.** {*;}

MitulVarmora commented 1 week ago
-keep class com.unsplash.pickerandroid.photopicker.** { *; }
-keep class io.reactivex.** {*;}

This proguard rules doesn't work on latest android project. I will have to create my own unsplash picker just because of no proper consumer proguard rules added to this library.

ChrisJan00 commented 1 week ago
-keep class com.unsplash.pickerandroid.photopicker.** { *; }
-keep class io.reactivex.** {*;}

This proguard rules doesn't work on latest android project. I will have to create my own unsplash picker just because of no proper consumer proguard rules added to this library.

There are new magical incantations to add to the proguard file, in addition to the known two lines:

-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
ChrisJan00 commented 1 week ago

I hope this fixes your issue @MitulVarmora

MitulVarmora commented 1 week ago
-keep class com.unsplash.pickerandroid.photopicker.** { *; }
-keep class io.reactivex.** {*;}

This proguard rules doesn't work on latest android project. I will have to create my own unsplash picker just because of no proper consumer proguard rules added to this library.

There are new magical incantations to add to the proguard file, in addition to the known two lines:

-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response

Great, Thanks. It worked.