gpt4 book ai didi

java - 由于没有 @Subcribe 方法,Android EventBus 应用程序在 Release模式下崩溃

转载 作者:行者123 更新时间:2023-12-01 09:14:35 47 4
gpt4 key购买 nike

该应用程序可以在调试中运行,但不能在发布中运行

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
这是我的混淆器文件:

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

我已经,ofc,用谷歌搜索了这个 - 但找不到任何结果。请询问您是否需要更多信息。

最佳答案

事实证明 @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();
}

关于java - 由于没有 @Subcribe 方法,Android EventBus 应用程序在 Release模式下崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40660685/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com