Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard configuration for Firebase-UI library

When creating a APK with proguard enabled, the following exception is thrown when using the FirebaseRecyclerAdapter from the Firebase-UI library (com.firebaseui:firebase-ui:0.3.0):

java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
                                                                              at com.firebase.ui.FirebaseRecyclerAdapter.onCreateViewHolder(FirebaseRecyclerAdapter.java:168)

The debug version (without proguard) works fine. Who has a working proguard config for Firebase-UI?

My current proguard config looks like this (only the Firebase related parts):

-optimizationpasses 5
-keepattributes SourceFile,LineNumberTable,Exceptions, Signature, InnerClasses,*Annotation*

-keepnames class ** { *; }

-keep class com.firebase.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
like image 313
Peter Avatar asked Dec 04 '22 01:12

Peter


2 Answers

Solved this by moving the ViewHolder classes that are used by the FirebaseRecyclerAdapter to a dedicated package (e.g. com.mypackage.myapp.viewholders) and adding a rule within the proguard configuration to prevent that classes within this package become obfuscated by proguard:

-keep class com.mypackage.myapp.viewholders.** { *; }
like image 115
Peter Avatar answered Jan 04 '23 04:01

Peter


Well, I had my ViewHolder inside relative FirebaseRecyclerAdapter as an inner class and gave me this error. Making the inner class has solved the problem.

Also https://github.com/firebase/FirebaseUI-Android/issues/46#issuecomment-167373575 states same thing with an addition.

Inner class ViewHolder must be public and static so that it could be initiated via reflection.

like image 37
guness Avatar answered Jan 04 '23 05:01

guness