Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in release mode caused by missing proguard rule #9

Open
ChrisJan00 opened this issue Aug 27, 2020 · 5 comments
Open

Crash in release mode caused by missing proguard rule #9

ChrisJan00 opened this issue Aug 27, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@ChrisJan00
Copy link

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.

@ChrisJan00 ChrisJan00 added the bug Something isn't working label Aug 27, 2020
@quocthinh212
Copy link

quocthinh212 commented Jun 28, 2022

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

@MitulVarmora
Copy link

-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
Copy link
Author

-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
Copy link
Author

I hope this fixes your issue @MitulVarmora

@MitulVarmora
Copy link

-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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants