其他分享
首页 > 其他分享> > Greenrobot Android Eventbus-没有选项eventbusindex传递给注释处理器

Greenrobot Android Eventbus-没有选项eventbusindex传递给注释处理器

作者:互联网

我正在尝试使用Greenrobot的Eventbus在Android应用程序中设置一个简单的订户,但是却遇到了gradle构建错误.我在下面显示了我的代码.

活动班

public final class OffersProcessedEvent {}

基本片段

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

活动发布

EventBus.getDefault().post(new OffersProcessedEvent());

订阅代码

@Subscribe
    public void onMessageEvent(OffersProcessedEvent event){
        *do whatever*
    }

以下是我的错误

构建Gradle错误

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 {
    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'
}

解决方法:

apply plugin: 'kotlin-kapt' // ensure kapt plugin is applied

dependencies {
    implementation 'org.greenrobot:eventbus:3.1.1'
    kapt 'org.greenrobot:eventbus-annotation-processor:3.1.1'
}

kapt {
    arguments {
        arg('eventBusIndex', 'com.example.myapp.MyEventBusIndex')
    }
}

标签:event-bus,subscribe,greenrobot-eventbus,android,greenrobot-eventbus-3-0
来源: https://codeday.me/bug/20191111/2017454.html