标签:
原文如下:
The android-apt plugin assists in working with annotation processors in combination with Android Studio. It has two purposes:
android-apt插件协助处理注解处理器结合Android工作室。它有两个目的:
This plugin requires the android or android-library plugin (version 0.7.x or up) to be configured on your project.
这个插件需要android或android库插件(版本0.7。x或)配置在您的项目。
Add the following to your build script to use the plugin:
增加一下内容到你的gradle构建文件中,让你能使用该插件
buildscript { repositories { mavenCentral() }
dependencies {
// replace with the current version of the Android plugin
替换为当前版本的Android插件
classpath ‘com.android.tools.build:gradle:0.7.3‘
// the latest version of the android-apt plugin
最新版本的android-apt插件
classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.2‘ }
}
apply plugin: ‘android‘apply plugin: ‘android-apt‘
Some annotation processor may require to pass custom arguments, you can use apt.argumentsfor that purpose. For instance Android Annotation library needs the following configuration:
一些注解处理器可能需要通过自定义参数,您可以使用apt.argumentsfor达到目的。比如Android注释库需要以下配置:
apt { arguments { resourcePackageName android.defaultConfig.packageName androidManifestFile variant.processResources.manifestFile }}
Make sure to configure packageName in the android defaultConfig block for this purpose. The arguments are processed for each variant when the compiler is configured. From this closure you can reference android, project and variant for the current variant.
确保配置packageName为此在android defaultConfig块。每个变量的参数处理时编译器配置。从这个闭包你可以参考android项目和变体为当前变体。
Annotation processors generally have a API and a processor that generates code that is used by the API. Depending on the project the processor and the API might be split up in separate dependencies. For example,Dagger uses two artifacts called dagger-compiler and dagger. The compiler artifact is only used during compilation, while the main dagger artifact is required at runtime.
To aid in configuring this dependency, the plugin adds a Gradle configuration named apt that can be used like this:
dependencies { apt ‘com.squareup.dagger:dagger-compiler:1.1.0‘ compile ‘com.squareup.dagger:dagger:1.1.0‘}
For annotation processors that include the API and processor in one artifact, there‘s no special setup. You just add the artifact to the compile configuration like usual and everything will work like normal. Additionally, if code that is generated by the processor is to be referenced in your own code, Android Studio will now correctly reference that code and resolve references to it.
对注解处理器在一个工件,包括API和处理器,没有特殊设置。你只需要添加工件编译配置像往常一样,一切都会正常工作。另外,如果处理器生成的代码是您自己的代码中引用,Android工作室现在将正确地引用代码和解决引用它。
标签:
原文地址:http://www.cnblogs.com/lvyerose/p/5333241.html