解决方案 把module/build.gradle下的apt插件应用全部注释掉 apply plugin: 'com.android.application' //apply plugin: 'android-apt classpath 'com.android.tools.build:gradle:3.5.2' // classpath 'com.neenbedankt.gradle.plugins:android-apt
build.gradle分别添加以下依赖,然而是错的 buildscript { dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt :1.8' } } apply plugin: 'com.neenbedankt.android-apt' 会出现以下错误,android-apt报警,该插件的作者在官网发表声明证实了后续将不会继续维护 android-apt,Google官方 插件提供了名为annotationProcessor的功能来完全代替android-apt Error:android-apt plugin is incompatible
Project)中的buildscript.dependecies添加: dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt 在build.gradle(Module)中紧挨着 apply plugin: 'com.android.application' 添加 apply plugin: 'android-apt' 然后在 permissionsdispatcher-processor:2.1.2" 整体看起来就像这样,带有**的表示需要添加的: apply plugin: 'com.android.application' **apply plugin: 'android-apt
repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt :1.8' } } 然后在你的项目里面使用 apply plugin: 'android-apt' android { ... } dependencies { compile 'com.jakewharton
在Project的build.gradle中添加apt命令 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' //添加apt命令 javax注解 如果同时依赖了butterknife那么可以采用如下的配置 apply plugin: 'com.android.application' //添加apt命令 apply plugin: 'android-apt
ButterKnife 简介 ButterKnife 总览 组件依赖关系 整体流 android-apt(Annotation Processing Tool) 三件套之注解处理器 小插曲之 UT 三件套之注册注解处理器 通过阅读 ButterKnife 源码和本文,你将收获: android-apt 三件套: 注解处理器(AbstractProcess) 注解处理器注册(AutoService) 代码生成(JavaPoet 5 android-apt(Annotation Processing Tool) 首先来解决第一个问题,编译期间和注解处理,通过这两个关键词,我们可以联想到的技术方案是: APT(Annotation ://github.com/google/auto/tree/master/service),此时只需要为注解处理器增加 @AutoService 注解就可以了,如下: AutoService 是为 android-apt 编译期间和运行期间相辅相成,这便是 android-apt 的普遍套路。 7 支持 library 编译时和运行时的问题解决了,还有最后一个问题:由 R 生成 R2 的意义是什么?
在讲解后在结合概念我们就能很好的理解了 ---- 引入 引入方法有2种: 第一种: 在工程的build.gradle文件中添加android-apt插件(该插件后面介绍) buildscript { dependencies { classpath 'com.android.tools.build:gradle:2.1.0' // 添加android-apt 插件 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } 在app的中的build.gradle文件中添加配置 android-apt是Gradle编译器的插件,根据其官方文档,主要两个目的: 编译时使用该工具,最终打包时不会将该插件打入到apk中。 能够根据设置的源路径,在编译时期生成相应代码。 在android-apt的文档中,也推荐使用这种方式。
1 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' module的build.gradle文件中删除 ? 3.0后,不支持apt问题 android studio更新到3.0后,不支持apt了,适配仅需要修改以下两点: 1.移除module目录下的build.gradle中的 apply plugin: 'android-apt
项目创建好后,在build.gradle(Project: HelloDagger)文件中的dependencies内添加 classpath 'com.neenbedankt.gradle.plugins:android-apt 文件中最外层的上方添加 apply plugin: 'com.neenbedankt.android-apt' 继续在该文件内的dependencies内添加 // apt command comes from the android-apt
这个时候就需要用到android-apt这个插件了,使用它有两个目的: 允许配置只在编译时作为注解处理器的依赖,而不添加到最后的APK或library 设置源路径,使注解处理器生成的代码能被Android Studio正确的引用 这里把使用ButterKnife时android-apt的配置作为例子,在工程的build.gradle中添加android-apt插件 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt :1.8' } } 在项目的build.gradle中添加 apply plugin: 'android-apt' android { ... } dependencies { compile generating-java-source-files-with-javapoet/ Java注解处理器 http://www.race604.com/annotation-processing/ android-apt
com.jakewharton:butterknife-gradle-plugin:8.8.1' // classpath 'com.neenbedankt.gradle.plugins:android-apt
com.android.tools.build:gradle:2.2.0' //这里配置 apt 供butterknife使用 classpath 'com.neenbedankt.gradle.plugins:android-apt classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.neenbedankt.gradle.plugins:android-apt com.jakewharton:butterknife-compiler:8.4.0' } 例如: apply plugin: 'com.android.application' apply plugin: 'android-apt 而ButterKnife使用的则是编译器时期注入,在使用的时候,需要配置classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’ , 这个配置说明
classpath 'com.android.tools.build:gradle:1.2.2' // replace with the current version of the android-apt plugin classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' } } repositories { mavenCentral() mavenLocal() } apply plugin: 'com.android.application' apply plugin: 'android-apt
consumer attributes: 解决方案: 1.在project的build.gradle中删除 classpath 'com.neenbedankt.gradle.plugins:android-apt :1.8' 2.在module的build.gradle中删除 apply plugin: 'android-apt' 3.将module的build.gradle文件中的dependency的apt
中添加 maven { url "https://www.jitpack.io" } 如下: classpath 'com.neenbedankt.gradle.plugins:android-apt
':apt-processor') } Android Gradle 插件 2.2 版本的发布,Android Gradle 插件提供了名为 annotationProcessor的功能来完全代替 android-apt 的 build.gradle中: buildscript { dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt Android 编译时注解-提升 Android APT及基于APT的简单应用 Android 打造编译时注解解析框架 这只是一个开始 你必须知道的APT、annotationProcessor、android-apt
build.gradle 文件中添加: buildscript { dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt :1.8' } } 然后在app module中的build.gradle中添加:(必须在app module中添加) apply plugin: 'android-apt' dependencies
android-apt android-apt是Android Studio中一款用来辅助处理编译时注解的Gradle插件。不知注解为何物的同学可以先下去补补课。 builg.gradle: apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' //引入android-apt 478_1508900811828.png] 结语 本文通过Adapter中使用工具类创建View的例子,一步一步讲解了如何通过自定义注解处理器,如何使用javaPoet提供的api,以及如何使用android-apt
所以要去除apt插件 apply plugin: 'android-apt' 需要 Build Tools 24.0.0 or later Error:Execution failed for task
build.gradle配置 打开app目录下的build.gradle,并加上一段编译代码 apply plugin: 'com.android.application' apply plugin: 'android-apt