繁体   English   中英

由于没有@Subcribe方法,Android 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.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

我肯定在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方法需要公开。

@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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM