greenrobot / EventBus

Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.
http://greenrobot.org/eventbus/
Apache License 2.0
24.68k stars 4.66k forks source link

[BUG][CRITICAL] R8 will delete all @Subscribe methods #625

Closed Duna closed 4 years ago

Duna commented 4 years ago

All @Subscribe methods gets deleted by using R8, no matter of proguard rules. All subscribe methods are public.

shrinkResources true
minifyEnabled true

Proguard rules:

-keepattributes *Annotation*
-keepclassmembers class * {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
    <init>(java.lang.Throwable);
}

This bug is critical since EventBus is no longer working with newest Android technologies

greenrobot-team commented 4 years ago

Thanks for reporting. This is a duplicate of #586.

Duna commented 4 years ago

Still anyone facing the issue? How did you solved it? gradle.properties: android.enableR8 = true gradle file:

        debug {
            minifyEnabled true
            shrinkResources false
            signingConfig signingConfigs.config
        }

Retrofit had the same issue: https://github.com/square/retrofit/issues/3005

Here it is the sample project that proves the EventBus is crashing the app. By default R8 is enabled in Android Studio 3.6.1. ProGuard is not used anymore since is deprecated.

Sample Project

Duna commented 4 years ago

https://square.github.io/okhttp/r8_proguard/ look what others do