Android 由于没有 @Subcribe 方法,EventBus 应用在发布模式下崩溃
Android EventBus app crashes in release mode due to no @Subcribe methods
该应用程序在调试中工作,但在发布时不工作
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.access0(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.access0(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
这是我的混淆器文件:
-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
我肯定在 MainActivity 中有 @Subscribe 函数:
@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();
}
我已经用谷歌搜索了这个 - 但找不到任何结果。
请询问您是否需要更多信息。
原来 @Subscribe 方法需要 public.
@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();
}
该应用程序在调试中工作,但在发布时不工作
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.access0(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.access0(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
这是我的混淆器文件:
-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
我肯定在 MainActivity 中有 @Subscribe 函数:
@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();
}
我已经用谷歌搜索了这个 - 但找不到任何结果。 请询问您是否需要更多信息。
原来 @Subscribe 方法需要 public.
@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();
}