EventBus3.0在androidstudio3.0上的配置

Abc
起因:
更新了androidStudio3.0后,用其打开以前的工程,会报错,有gradle的问题,有编译版本的问题,还有apt的问题:
apt(annotation processing tool) –> annotationProcessor

这一点导致之前项目里的gradle配置都不能直接使用了。需要修改一下:

1. 修改Project 的build.gradle配置

android-apt方式

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }

annotationProcessor方式(删除apt的引用):

dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }

2. 修改module的build.gradle配置
apt方式:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
    compile 'org.greenrobot:eventbus:3.0.0'
    apt'org.greenrobot:eventbus-annotation-processor:3.0.1'
}

annotationProcessor方式 (只保留dependencies 里面的引用并且把apt 换成annotationProcessor) :

dependencies {
    compile 'org.greenrobot:eventbus:3.0.0'
    annotationProcessor  'org.greenrobot:eventbus-annotation-processor:3.0.1'
}

3. dependencies里的配置:

apt方式:

apt 'org.greenrobot:eventbus-annotation-processor:3.0.1'

annotationProcessor方式 (apt 替换为:annotationProcessor):

annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.0.1'

4. EventBus 3.0 注解索引参数配置

apt方式:

}apt {
    arguments {
        eventBusIndex "com.cyun.demo.MyEventBusIndex" //eventbus注解特性需要的索引
    }

annotationProcessor方式(
1 defaultConfig节点下:增加jackOptions和javaCompileOptions

):

defaultConfig {
        applicationId "com.cyun.demo"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 420
        versionName "4.2.0.0"

        jackOptions {
                enabled true
            }
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [ eventBusIndex: 'com.cyun.demo.MyEventBusIndex'] //eventbus注解特性需要的索引
            }
        }
   }

另外,android studio3.0 编译版本选择Java 8的话必须使用Jack编译,android-apt只支持javac编译而annotationProcessor既支持javac同时也支持jack编译。

参考文章:

  1. https://www.cnblogs.com/whoislcj/p/6148410.html
  2. http://blog.csdn.net/u012987766/article/details/78394439
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值