- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在库中有一个带注释的 Activity,它是同一库中 EventBus 事件的订阅者。它看起来像这样,大大简化了:
@EActivity(resName = "activity_foo")
public class Foo extends Activity {
public void onEvent(BarEvent event){
doSomething();
}
}
它应该按照这个工作:
http://timnew.me/blog/2014/09/14/otto-and-android-annotations-compatibility-issue-analysis/
但实际上它返回了这个错误:
Unable to start activity ... de.greenrobot.event.EventBusException: Subscriber class com.foo.bar.activities.Foo_ has no public methods called onEvent
EventBus 似乎没有在父类中查找。我猜每个人都在谈论的@Subscribe 注解只存在于 Guava 和 Otto 中,而没有存在于 EventBus 中。网上没有人在谈论 AA 和 Eventbus 之间的兼容性问题,所以我一定遗漏了什么。
我怎样才能让它工作?
事件总线:2.4
机管局:3.2
编辑:
在 WonderCsabo 的回答后,我将 EventBus 更新到 3.0 beta(包括 Subscribe 注释)并将 AA 更新到 3.3.1,问题消失了,但还有另一个问题:
java.lang.NoSuchFieldError
at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:688)
at libcore.reflect.AnnotationAccess.getDefaultValue(AnnotationAccess.java:361)
at java.lang.reflect.Method.getDefaultValue(Method.java:327)
at libcore.reflect.AnnotationFactory.getElementsDescription(AnnotationFactory.java:75)
at libcore.reflect.AnnotationFactory.<init>(AnnotationFactory.java:112)
at libcore.reflect.AnnotationFactory.createAnnotation(AnnotationFactory.java:94)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:666)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
at java.lang.reflect.Method.getAnnotation(Method.java:301)
at de.greenrobot.event.n.b(SourceFile:133)
at de.greenrobot.event.n.a(SourceFile:79)
at de.greenrobot.event.c.a(SourceFile:135)
at com.babestudios.lib.lq.activities.f.onStart(SourceFile:515)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
at android.app.Activity.performStart(Activity.java:6006)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NoSuchFieldException: PostThread
at java.lang.Class.getDeclaredField(Class.java:890)
at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:685)
at libcore.reflect.AnnotationAccess.getDefaultValue(AnnotationAccess.java:361)
at java.lang.reflect.Method.getDefaultValue(Method.java:327)
at libcore.reflect.AnnotationFactory.getElementsDescription(AnnotationFactory.java:75)
at libcore.reflect.AnnotationFactory.<init>(AnnotationFactory.java:112)
at libcore.reflect.AnnotationFactory.createAnnotation(AnnotationFactory.java:94)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:666)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
at java.lang.reflect.Method.getAnnotation(Method.java:301)
at de.greenrobot.event.n.b(SourceFile:133)
at de.greenrobot.event.n.a(SourceFile:79)
at de.greenrobot.event.c.a(SourceFile:135)
at com.babestudios.lib.lq.activities.f.onStart(SourceFile:515)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
at android.app.Activity.performStart(Activity.java:6006)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
我注意到这两个问题(丢失的 onEvent 和现在的 PostThread 只是发布版本的问题。我使用 ProGuard,但 EventBus 和 AA 有推荐的异常(exception))。
编辑 2:
我加了
-keep class de.greenrobot.** {*;}
它似乎在工作。
最佳答案
我有 EventBus 注释用于:
# Ensure annotations are kept for runtime use.
-keepattributes *Annotation*
# Don't remove any GreenRobot classes
-keep class de.greenrobot.** {*;}
# Don't remove any methods that have the @Subscribe annotation
-keepclassmembers class ** {
@de.greenrobot.event.Subscribe <methods>;
}
请注意,这还可以确保您的方法名称仍然会被混淆。
关于AndroidAnnotations 和 EventBus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30990480/
我正在尝试从 AndroidAnnotations 3.3.2 升级到版本 4.0.0,但在升级后让 ORMLite 工作时遇到问题。升级到 4.0.0 并构建项目后,我收到错误消息:“错误:找不到符
我想将我的应用程序的某些部分提取到库中,但 AndroidAnnotations 不允许我 ;-) 如果我有: App - uses AndroidAnnotations - uses
我在 Android Studio gradle 项目中使用 AndroidAnnotations。我目前在编译期间从 AA 得到错误输出: cannot find symbol class MyAc
我有一个扩展父 fragment (NavMenu) 的 fragment (NavMenuStats)。 这个父 fragment 重写 onCreateView 方法,如下所示: @Nullabl
我在我的应用程序中使用 AndroidAnnotations,当我尝试将额外内容放入 Intent 并启动一个使用 AndroidAnnotations 的 Activity 时,我总是会收到运行时错
我用这个expandable recycler view库和 Android 注释。并尝试使用@NonConfigurationInstance注释。在 ItemViewHolder 类构造函数中,我
我在库中有一个带注释的 Activity,它是同一库中 EventBus 事件的订阅者。它看起来像这样,大大简化了: @EActivity(resName = "activity_foo") publ
我正在使用 Android Annotations RestService 进行 API 调用。唯一的问题是我收到了一个 JSON,但我不知道如何查看该 JSON 字符串。有没有一种方法可以查看响应数
所以我想尝试新的 Android Studio 并导入我的 eclipse 项目(我生成了一个 gradle 构建文件)。效果不错。 似乎唯一不起作用的库是 AndroidAnnotations。我在
如何将自定义操作栏布局与 AndroidAnnotations 结合使用? 有效的代码: @EActivity(R.layout.activity_register_classes) public c
我正在使用 AndroidAnnotation 开发 Android 应用程序。 应用程序对我的远程 API 进行 REST 调用。所以我设置了 AA 和我的 REST 客户端。但我想编写通用代码来处
我正在尝试使用 AndroidAnnotations 的 RestClient,但是当我调用客户端中的方法之一时,出现以下错误: 04-10 10:07:23.624 7528-7528/eu.
我有一个用 @Rest 注释的类,我在另一个实例中使用它的方法,用 @RestService 注释。当我调用 Rest 客户端类的某些方法时,出现 NetworkOnMainThreadExcepti
我有一个 Android 应用程序,我想下载一个大文件。 REST API 实现是通过 AndroidAnnotations 实现的。我需要使用此 REST 客户端(由 AndroidAnnotati
我正在尝试使用 AndroidAnnotations 创建一个简单的学习项目,它将与 REST 调用一起使用。我已经按照这个教程 https://github.com/androidannotatio
我有一个继承自 ListActivity 并使用 AndroidAnnotations 的 Activity 。虽然 .onListItemClick 工作正常,但列表项的上下文菜单根本没有出现,甚至
当RoboGuice触发事件时,我的事件回调会在哪里执行,在哪个线程?例如,我有一个具有 do(@Observes OnUpdateUiEvent e) 的 Activity 。我还有一个触发新 On
好的。 我正在尝试创建一个可以通过使用 maven 且仅使用 maven 来完美构建的项目。 目前,只要在实际 Java 代码中没有引用,我就面临着正在生成类并且工作正常的问题。 意思是,如果我在 d
我正在阅读有关依赖注入(inject)的文章,发现了 2 个引起我注意的库,AndroidAnnotations 和 Dagger 2。我看到的是 AA 具有很多功能,包括 DI,但是大多数开发人员都
我在使用 AndroidAnnotations 构建 Activity 时遇到了一些麻烦。我有一个名为 TemplateActivity 的父 Activity : @EActivity(R.layo
我是一名优秀的程序员,十分优秀!