I'm using AndroidStudio 3.1 Canary 3 at the moment along with D8. I've tried without D8 and have tried 3.1.0 also. The consistent issue is that MAIN_ORDERED throws an error in the annotation processor where it can't find the ENUM. However, when I check the EventBus code, the ENUM is there. Android Studio also auto-completes the MAIN_ORDERED enum.
In my Activity I have:
@Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
public void fragmentDone(FragmentResult msg) {
This fails to build with an error from the annotation processor:
07:28:26.857 [ERROR] [system.err] error: Unexpected error in EventBusAnnotationProcessor: java.lang.EnumConstantNotPresentException: org.greenrobot.eventbus.ThreadMode.MAIN_ORDERED
which goes away if I revert to using ThreadMode.MAIN
.
I'm building using the org.greenrobot:eventbus:3.1.1
and org.greenrobot:eventbus-annotation-processor:3.1.0
which seems to be the correct version.
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)
This results in a broken EventBusIndex.java file being generated:-
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[] {
And again, looking at the import org.greenrobot.eventbus.ThreadMode;
file, the enum looks to include the MAIN_ORDERED
declaration.
I'm out of ideas...
An update has been released for the EventBusAnnotationProcessor.
Please check the issue thread.
Gradle dependency
annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.1.1'
Successfully Generated Index
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;
}
}
}