Android android-apt切换annotationProcessor

Android Studio 2.2 Gradle 插件提供了annotationProcessor 的功能来代替 android-apt . android-apt 后续将不会继续维护. 所以将android-apt切换annotationProcessor。

  • Android Gradle 插件版本升级到 2.2(含)以上。
  • 并移除根目录的 build.gradle 中的android-apt。
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        //classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        //删除 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}
  • 移除Module里build.gradle中android-apt配置
//删除 apply plugin: 'com.neenbedankt.android-apt'
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.4.0'
    // update apt to annotationProcessor
    //apt 'com.google.dagger:dagger-compiler:2.2'
    //将apt依赖修改为annotationProcessor
    annotationProcessor 'com.google.dagger:dagger-compiler:2.2'
    compile 'com.google.dagger:dagger:2.2
}
  • annotationProcessor 参数适配,兼容EventBus3.
    原APT配置参数方式
apt  {
    arguments {
        eventBusIndex "org.greenrobot.eventbusperf.MyEventBusIndex"
    }
}

修改为:在defaultConfig节点下添加javaCompileOptions

defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [ eventBusIndex : 'org.greenrobot.eventbusperf.MyEventBusIndex' ]
            }
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容