Redex: problem with firebase

Created on 6 Oct 2016  路  15Comments  路  Source: facebook/redex

I've this runtimeException:

10-06 13:58:42.867 E/AndroidRuntime(25200): java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.IllegalStateException: com.google.firebase.auth.FirebaseAuth#getInstance has been removed by Proguard. Add keep rule to prevent it. 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.app.ActivityThread.installProvider(ActivityThread.java:5216) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4808) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4748) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.app.ActivityThread.-wrap1(ActivityThread.java) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.os.Handler.dispatchMessage(Handler.java:102) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.os.Looper.loop(Looper.java:148) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.app.ActivityThread.main(ActivityThread.java:5480) 10-06 13:58:42.867 E/AndroidRuntime(25200): at java.lang.reflect.Method.invoke(Native Method) 10-06 13:58:42.867 E/AndroidRuntime(25200): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 10-06 13:58:42.867 E/AndroidRuntime(25200): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 10-06 13:58:42.867 E/AndroidRuntime(25200): Caused by: java.lang.IllegalStateException: com.google.firebase.auth.FirebaseAuth#getInstance has been removed by Proguard. Add keep rule to prevent it. 10-06 13:58:42.867 E/AndroidRuntime(25200): at com.google.firebase.FirebaseApp.a(Unknown Source) 10-06 13:58:42.867 E/AndroidRuntime(25200): at com.google.firebase.FirebaseApp.a(Unknown Source) 10-06 13:58:42.867 E/AndroidRuntime(25200): at com.google.firebase.FirebaseApp.a(Unknown Source) 10-06 13:58:42.867 E/AndroidRuntime(25200): at com.google.firebase.FirebaseApp.a(Unknown Source) 10-06 13:58:42.867 E/AndroidRuntime(25200): at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.content.ContentProvider.attachInfo(ContentProvider.java:1748) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.content.ContentProvider.attachInfo(ContentProvider.java:1723) 10-06 13:58:42.867 E/AndroidRuntime(25200): at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) 10-06 13:58:42.867 E/AndroidRuntime(25200): at android.app.ActivityThread.installProvider(ActivityThread.java:5213) 10-06 13:58:42.867 E/AndroidRuntime(25200): ... 10 more

without redex, the release apk with proguard active, is working.

bug

Most helpful comment

Not working for me now. Anyone find solution for this, please paste it here.

All 15 comments

How are you running redex? Are you correctly pointing it at your proguard config?

the problem appaered when my app has become multidex in release mode

buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro','proguard-rx.pro', 'proguard-smack.pro'
            signingConfig signingConfigs.release
        }
    ....

in proguard-rules.pro I have:

...
#firebase auth
# Recommended flags for Firebase Auth
-keepattributes Signature
-keepattributes *Annotation*
-keepclasseswithmembers class * {
    public static FirebaseAuth getInstance ();
}
...

my commandline are these:
#redex -o app-release-redex.apk app-release.apk --sign -s ./xxxx.jks -a xxxx -p xxxx -k keepme.txt -P proguard-rules.pro

#redex -o app-release-redex.apk app-release.apk --sign -s ./xxxx.jks -a xxxx -p xxxx -k keepme.txt

#redex -o app-release-redex.apk app-release.apk --sign -s ./xxxx.jks -a xxxx -p xxxx

my keepme.txt was that:
com.google.firebase.auth.FirebaseAuth

in the app-release-redex.apk there is the method getInstance() (see

image
)

In all tests:

  • the app-release.apk is OK
  • the app-release-redex.apk fails

I'm using always the last commit of redex, like today:

commit 18fdc1a10602d1835eec1bad053ca8636bd95720
Author: Brian Long <[email protected]>
Date:   Mon Nov 21 15:06:41 2016 -0800

PS: I'm using redex in other project with success

I added this in proguard and it worked

-keepattributes Signature
-keepattributes *Annotation*
-keepclasseswithmembers class * {
    public static FirebaseAuth getInstance ();
}
-keep class com.google.firebase.auth.FirebaseAuth

and i am not doing this -k keepme.txt as well while generating redex apk

no, even with your changes, the generated redex apk fails with the same exception

+1

Not working for me now. Anyone find solution for this, please paste it here.

@samyakjain , is your app overflow the 64k methods?

No, but multiDexEnabled is true, because app overflow 64k methods in debug

Try adding @DoNotStrip. See the readme for details.

@justinjhendrick this class is from a closed source external library, how can someone apply that annotation on code they don't control?

Trying just telling redex to use the androidx Keep annotation

Index: path/to/app/redex_config.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- path/to/app/redex_config.json   (date 1548926421000)
+++ path/to/app/app-apk/redex_config.json   (date 1548998131000)
@@ -8,5 +8,13 @@
   "InterDexPass" : {
     "normal_primary_dex" : "false"
   },
-  "coldstart_classes" : "path/to/list/redex_classlist.txt"
+  "coldstart_classes" : "path/to/list/redex_classlist.txt",
+  "keep_annotations": [
+    "Landroidx/annotation/Keep;"
+  ],
+  "RenameClassesPassV2" : {
+    "dont_rename_annotated": [
+      "Landroidx/annotation/Keep;"
+    ]
+  }
 }

will report back findings. I know that this DoNotStrip annotation exists in some Facebook SDKs though, so it's possible that specifying only 1 may be limiting.

CC @awelc

It appears that even with adding that to our config, it's not respecting that annotation (at least in the version of redex we're using). I'll talk with @awelc separately first to make sure I'm not missing something on our end

You can also add a proguard rule and pass the proguard file to redex with -P

If you weren't using a proguard file before this, adding a proguard file may enable some more optimizations.

To check which new optimizations will run, before you add -P, enable logging with export TRACE=1 then look for prints like:

"Pass not run because no ProGuard configuration was provided."
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hljwang3874149 picture hljwang3874149  路  4Comments

maocanmao picture maocanmao  路  6Comments

VenomVendor picture VenomVendor  路  7Comments

amiton picture amiton  路  5Comments

awelc picture awelc  路  3Comments