EventBus 3
最新推出的3.0版本 加入了 EventBusAnnotationProcessor (注解分析生成索引) 技术,提高了效率
所以3.0版本配置起来 会麻烦一些,如果嫌麻烦的话,可以不用这个注解,但是如果是这样的话,效率会很低,不如用2.4版本
2.4版本很简单 直接添加jar包就行了
3.0版本 添加完jar之后
在Project下的,build.gradle文件中的buildscript 添加 path
buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }
再到app下的 build.gradle中 添加如下代码
arguments 里面设置 apt 生成的索引的包名和类名
apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' apt { arguments { eventBusIndex "com.demon.testservice.MyEventBusIndex" } }
在 dependencies中 添加
注解这个jar 暂时不知道如何添加 只能apt这样在线添加
compile files('libs/eventbus-3.0.0.jar') apt 'org.greenrobot:eventbus-annotation-processor:3.0.1'
Rebuild Project 之后 就能在项目的如下路径中看到 注解生成的 MyEventBusIndex.java
app\build\generated\source\apt\debug\com\demon\testservice
最后在Application中 生成的索引 设置给EventBus的默认单例中
public class App extends Application { @Override public void onCreate() { super.onCreate(); EventBus.builder().addIndex(new MyEventBusIndex()).installDefaultEventBus(); } }
这样3.0版本就配置完毕了
参考
老司机教你 “飙” EventBus 3 - Powered by Bugly!
http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=938&fromuid=1147
来不及解释了,快上车之EventBus3.0更多实用使用 - 简书
http://www.jianshu.com/p/72f475ac3a8d