我目前正在使用AndroidStudio 3.1 Canary 3以及D8。我已经尝试过没有D8并尝试过3.1.0。一致的问题是MAIN_ORDERED在注释处理器中抛出一个错误,它无法找到ENUM。但是,当我检查EventBus代码时,ENUM就在那里。 Android Studio还会自动完成MAIN_ORDERED枚举。
在我的活动中,我有:
@Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
public void fragmentDone(FragmentResult msg) {
这无法使用注释处理器中的错误进行构建:
07:28:26.857 [ERROR] [system.err] error: Unexpected error in EventBusAnnotationProcessor: java.lang.EnumConstantNotPresentException: org.greenrobot.eventbus.ThreadMode.MAIN_ORDERED
ThreadMode.MAIN
,会消失。
我使用似乎是正确版本的org.greenrobot:eventbus:3.1.1
和org.greenrobot:eventbus-annotation-processor:3.1.0
进行构建。
20:47:37.023 [ERROR] [system.err] java.lang.EnumConstantNotPresentException: org.greenrobot.eventbus.ThreadMode.MAIN_ORDERED
20:47:37.129 [ERROR] [system.err] at sun.reflect.annotation.EnumConstantNotPresentExceptionProxy.generateException(EnumConstantNotPresentExceptionProxy.java:46)
20:47:37.130 [ERROR] [system.err] at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:84)
20:47:37.130 [ERROR] [system.err] at com.sun.proxy.$Proxy142.threadMode(Unknown Source)
20:47:37.130 [ERROR] [system.err] at org.greenrobot.eventbus.annotationprocessor.EventBusAnnotationProcessor.writeCreateSubscriberMethods(EventBusAnnotationProcessor.java:287)
20:47:37.130 [ERROR] [system.err] at org.greenrobot.eventbus.annotationprocessor.EventBusAnnotationProcessor.writeIndexLines(EventBusAnnotationProcessor.java:373)
20:47:37.130 [ERROR] [system.err] at org.greenrobot.eventbus.annotationprocessor.EventBusAnnotationProcessor.createInfoIndexFile(EventBusAnnotationProcessor.java:333)
20:47:37.130 [ERROR] [system.err] at org.greenrobot.eventbus.annotationprocessor.EventBusAnnotationProcessor.process(EventBusAnnotationProcessor.java:106)
20:47:37.130 [ERROR] [system.err] at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
20:47:37.130 [ERROR] [system.err] at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
这会导致生成一个损坏的EventBusIndex.java文件: -
package com.company.product;
import org.greenrobot.eventbus.meta.SimpleSubscriberInfo;
import org.greenrobot.eventbus.meta.SubscriberMethodInfo;
import org.greenrobot.eventbus.meta.SubscriberInfo;
import org.greenrobot.eventbus.meta.SubscriberInfoIndex;
import org.greenrobot.eventbus.ThreadMode;
import java.util.HashMap;
import java.util.Map;
/** This class is generated by EventBus, do not edit. */
public class EventBusIndex implements SubscriberInfoIndex {
private static final Map<Class<?>, SubscriberInfo> SUBSCRIBER_INDEX;
static {
SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>();
putIndex(new SimpleSubscriberInfo(com.company.product.activities.MainActivity.class, true,
new SubscriberMethodInfo[] {
再次,查看import org.greenrobot.eventbus.ThreadMode;
文件,枚举看起来包含MAIN_ORDERED
声明。
我没有想法......
答案 0 :(得分:2)
已发布 EventBusAnnotationProcessor 的更新
请检查问题thread。
Gradle依赖
annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.1.1'
成功生成索引
import org.greenrobot.eventbus.meta.SimpleSubscriberInfo;
import org.greenrobot.eventbus.meta.SubscriberMethodInfo;
import org.greenrobot.eventbus.meta.SubscriberInfo;
import org.greenrobot.eventbus.meta.SubscriberInfoIndex;
import org.greenrobot.eventbus.ThreadMode;
import java.util.HashMap;
import java.util.Map;
/** This class is generated by EventBus, do not edit. */
public class MyEventBusIndex implements SubscriberInfoIndex {
private static final Map<Class<?>, SubscriberInfo> SUBSCRIBER_INDEX;
static {
SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>();
putIndex(new SimpleSubscriberInfo(MainActivity.class, true, new SubscriberMethodInfo[] {
new SubscriberMethodInfo("onEvent", MainActivity.TestEvent.class, ThreadMode.MAIN_ORDERED),
}));
}
private static void putIndex(SubscriberInfo info) {
SUBSCRIBER_INDEX.put(info.getSubscriberClass(), info);
}
@Override
public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) {
SubscriberInfo info = SUBSCRIBER_INDEX.get(subscriberClass);
if (info != null) {
return info;
} else {
return null;
}
}
}