Search code examples
androidproguardroboguice

RoboGuice @Observes do not work in release build


I'm using RoboGuice's EventManager in my app as shown here https://code.google.com/p/roboguice/wiki/Events#Creating_your_Own_Events

and it works perfectly in debug build, but the events do not trigger in release build - probably due to ProGuard obfuscation.

I tried to keep the relevant methods and classes from ProGuard's handling, but I guess I'm doing something wrong:

This is what I tried ProGuard config

-keep class com.myapp.events.*                          # keep all the event classes
-keepclasseswithmembers class * { void on*Event(*); }   # keep methods named on*Event,  eg. onUserClickedEvent

my main activity class has handlers such as:

public void onUserClickedEvent( @Observes UserClicked  event) {
    ...
}

Solution

  • Solved after reading more about Proguard... I changed functions signature and modified the Proguard config to this:

    -keep class com.myapp.events.*  
    -keepclasseswithmembers class * { 
       void onEvent*(...); 
    }