uber/RxDogTag

Issue with Proguard and AGP 7.0.2 (RxDogTag 1.0.1)

Closed this issue · 5 comments

We recently encountered a weird issue after upgrading to the Android Gradle Plugin 7.0.2. When running our release build and therefore Proguard, the application crashes right at the start of the application with an ExceptionInInitializerError when RxDogTag.install() is called.

Stacktrace:

java.lang.ExceptionInInitializerError
        at com.uber.rxdogtag.RxDogTag$Builder.install(:483)
        at com.uber.rxdogtag.RxDogTag.install(:103)
        at com.mikef.rxdogtagissue.DogTagApplication.onCreate(:12)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
        at android.app.ActivityThread.access$1300(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Package.getName()' on a null object reference
        at com.uber.rxdogtag.RxDogTag$Configuration.<clinit>

After investigating this issue a little bit I found the root cause in our Proguard configuration:

-repackageclasses ''

When this is set the aforementioned issue occurs. When going back to AGP 4.2.2 there is no issue, same thing when we remove this flag. I can't tell exactly why exactly this happens and whether it is the fault of RxDogTag or the Android Gradle Plugin.
For we now we removed this Proguard flag in order to solve the issue.

I've also created a super simple sample repository in order to reproduce this issue.

Library version:
1.0.1

it looks like R8 3+ (which is bundled with AGP 7) doesn't respect the keeppackagenames directive (which is used in RxDogTag's rxdogtag.pro) when the repackageclasses is enabled. The simplest way to solve this is to duplicate directives from the rxdogtag.pro using the keepnames instead of keeppackagenames:

-keepnames class com.uber.rxdogtag.**
-keepnames class io.reactivex.**

it shouldn't interfere with the shrinking process, but the class names won't be obfuscated also

Sorry for the delay on this, I didn't have notifications enabled here. PR welcome!

@ZacSweers done, 2 PRs for both main and 1.x branches:
#74 and #75

Merged the two PRs, will work on cutting releases today

Released as 2.0.2 and 1.0.2. Thanks!