確實是好東西,別人沒翻譯我來代勞一下~~~

關於android-apt

原文以下:html

What is this?

這是什麼?

 

The android-apt plugin assists in working with annotation processors in combination with Android Studio. It has two purposes:android

android-apt插件協助處理註解處理器結合Android工做室。它有兩個目的:git

  • Allow to configure a compile time only annotation processor as a dependency, not including the artifact in the final APK or library
  • 容許在項目中配置編譯時的註解處理器依賴管理,不會將這個artifact打包到最終的APK或library中去
  • Set up the source paths so that code that is generated from the annotation processor is correctly picked up by Android Studio.
  • 設置生成的代碼註解處理器的source路徑,可以正確被Android studio引用

This plugin requires the android or android-library plugin (version 0.7.x or up) to be configured on your project.github

這個插件須要android或android庫插件(版本0.7。x或)配置在您的項目。閉包

Including and using the plugin in your build script

內容和使用這個插件在你的構建腳本中(gradle)

Add the following to your build script to use the plugin:app

增長一下內容到你的gradle構建文件中,讓你能使用該插件maven

buildscript { repositories { mavenCentral() }ide

dependencies {gradle

// replace with the current version of the Android pluginui

替換爲當前版本的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'

Passing processor arguments

經過處理器參數

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項目和變體爲當前變體。

Configurating a compiler style dependency

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'}

Configuration of other annotation processors

配置的其餘註解處理器

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工做室如今將正確地引用代碼和解決引用它。

相關文章
相關標籤/搜索