I'm trying to set up a simple subscriber in my Android application using Greenrobot's Eventbus, but I am getting a gradle build error. I have shown my code below.
Event class
public final class OffersProcessedEvent {}
Base Fragment
public class BaseFragment extends Fragment {
private boolean registered;
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
EventBus.getDefault().register(this);
registered = true;
}
@Override
public void onResume() {
super.onResume();
if (!registered) {
EventBus.getDefault().register(this);
registered = true;
}
}
@Override
public void onPause() {
super.onPause();
EventBus.getDefault().unregister(this);
registered = false;
}
public AppCompatActivity getAppCompatActivity() {
return (AppCompatActivity) getActivity();
}
}
Event post'
EventBus.getDefault().post(new OffersProcessedEvent());
Subscribe code
@Subscribe
public void onMessageEvent(OffersProcessedEvent event){
*do whatever*
}
The following are my errors
Build Gradle Errors
Error:No option eventBusIndex passed to annotation processor
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Gradle dependencies
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.jakewharton:butterknife:8.6.0'
compile 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.jakewharton:butterknife:8.7.0'
compile 'com.jakewharton:butterknife-compiler:8.7.0'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:cardview-v7:26.0.0-alpha1'
compile 'com.google.code.gson:gson:2.8.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'org.greenrobot:eventbus-annotation-processor:3.0.1'
}
Base on this link http://greenrobot.org/eventbus/documentation/faq/
So you must add
But is you steel getting
Error:No option eventBusIndex passed to annotation processor
Add this to your
app.gradle
If using annotationProcessor
If using kapt
And if using android-apt
And this file will be generate by EventBus
Hope it's help