从android-apt切换到annotationProcessor
来源:互联网 发布:java server error 编辑:程序博客网 时间:2024/06/06 01:10
项目中的EventBus ,Butterknife…等框架都采用了android-apt注解预编译的方式(在编译期生成代码,提高效率),Android Studio推出了官方插件annotationProcessor,并且可以通过gradle来简单的配置;所以apt的作者早已经宣布不再维护了,但是在项目中一直没有替换,最近抽空将apt,替换成了annotationProcessor
首先要确保Android Gradle插件版本是2.2以上
接下来开始修改配置
修改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
dependencies { classpath 'com.android.tools.build:gradle:2.2.3' }
修改模块中的依赖
由于我们的项目是多组件多个模块,所以Eventbus,Butterknife依赖都添加在CommonLib中,以Eventbus为例:
android-apt方式
apply plugin: 'com.neenbedankt.android-apt'buildscript { repositories { jcenter() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' }}dependencies { compile 'org.greenrobot:eventbus:3.0.0' apt'org.greenrobot:eventbus-annotation-processor:3.0.1'//apt}
修改后annotationProcessor 方式,只保留dependencies 里面的引用并且把apt 换成annotationProcessor就可以了
dependencies { compile 'org.greenrobot:eventbus:3.0.0' annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.0.1'}
这里要注意的是
关于Eventbus的MyEventBusIndex
android-apt方式
apt { arguments { eventBusIndex "com.xxx.xxx.MyEventBusIndex" }}
修改后annotationProcessor 方式
defaultConfig { javaCompileOptions { annotationProcessorOptions { arguments = [ eventBusIndex : 'com.xxx.xxx.MyEventBusIndex' ] } } }
注意:如果采用在基础模块中配置的,一定要在使用的其他模块中配置,不然不能生成代码
annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.0.1'
阅读全文
0 0
- 从android-apt切换到annotationProcessor
- android-apt切换为官方annotationProcessor
- Android使用注解之注解编译android-apt如何切换到annotationProcessor
- Android注解使用之注解编译android-apt如何切换到annotationProcessor
- Android注解使用之注解编译android-apt如何切换到annotationProcessor
- Android注解使用之注解编译android-apt如何切换到annotationProcessor
- Android Apt与annotationProcessor
- 为什么用annotationProcessor代替android-apt?
- 深入理解编译注解(二)annotationProcessor与android-apt
- ButterKnife绑定失败?android-apt没用?尝试用一下annotationProcessor
- android-apt和annotationProcessor的使用以及互换
- android-apt plugin is incompatible with the Android Gradle plugin. Please use 'annotationProcessor'
- 使用编译时注解annotationProcessor(取代android-apt)开发组件化路由框架
- 从iOS切换到Android(flyme)
- 从病毒、木马到APT
- Android Studio从2.3升级到3.0之后apt报错
- 从ActionBar切换到toolBar
- Android 利用annotationProcessor生成Java代码
- Python中的装饰器
- 虚拟机ubuntu安装gitlab
- 马化腾:谈谈我创办腾讯这些年
- 逻辑回归原理
- Degree of an Array问题及解法
- 从android-apt切换到annotationProcessor
- HTML表单
- 菜鸟先飞之JAVA_多线程
- network Tools
- linux centos shell脚本自动化部署jdk
- linux进程间通信之信号量
- python经常管理supervisor简单介绍
- 报名 | 东南大学周张泉:基于知识图谱的推理技术
- 【第七周项目6】停车场模拟