Приложение Android EventBus не работает в режиме выпуска из-за отсутствия методов @Subcribe
Приложение работает в режиме отладки, но не в версии
Process: com.rubenwardy.monzolytics, PID: 14943
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rubenwardy.monzolytics/com.rubenwardy.monzolytics.MainActivity}: org.greenrobot.eventbus.EventBusException: Subscriber class com.rubenwardy.monzolytics.MainActivity and its super classes have no public methods with the @Subscribe annotation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2344)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class com.rubenwardy.monzolytics.MainActivity and its super classes have no public methods with the @Subscribe annotation
at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:67)
at org.greenrobot.eventbus.EventBus.register(EventBus.java:136)
at com.rubenwardy.monzolytics.MainActivity.onStart(MainActivity.java:88)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
at android.app.Activity.performStart(Activity.java:5992)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Вот мой файл Gradle: https://gist.github.com/rubenwardy/b467d1efd79c671f9a932d98768ff656
Вот мой файл proguard:
-keep class com.androidplot.** { *; }
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
-keepclassmembers class com.rubenwardy.** { *; }
Ошибка все еще происходит, если я заменю proguard на это:
-dontoptimize
-dontshrink
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
У меня определенно есть функции @Subscribe в MainActivity:
@Subscribe
protected void onPeriodChange(final Events.PeriodChangeRequestedEvent e) {
Log.e("MAct", "Period " + e.from.toString() + " to " + e.to.toString());
filter = new TransactionFilter() {
@Override
public boolean isAllowed(Transaction transaction) {
return transaction.created.getTime() > e.from.getTime() &&
transaction.created.getTime() < e.to.getTime();
}
};
filterTransactions();
}
Я, конечно, гуглил это - но не могу найти никаких результатов. Пожалуйста, спросите, если вам нужна дополнительная информация.
1 ответ
Решение
Оказывается, методы @Subscribe должны быть публичными.
@Subscribe
public void onPeriodChange(final Events.PeriodChangeRequestedEvent e) {
Log.e("MAct", "Period " + e.from.toString() + " to " + e.to.toString());
filter = new TransactionFilter() {
@Override
public boolean isAllowed(Transaction transaction) {
return transaction.created.getTime() > e.from.getTime() &&
transaction.created.getTime() < e.to.getTime();
}
};
filterTransactions();
}