zoukankan      html  css  js  c++  java
  • 确实是好东西,别人没翻译我来代劳一下~~~

    关于android-apt

    原文如下:

    What is this?

    这是什么?

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

    android-apt插件协助处理注解处理器结合Android工作室。它有两个目的:

    • 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.

    这个插件需要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:

    增加一下内容到你的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'

    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工作室现在将正确地引用代码和解决引用它。

     

  • 相关阅读:
    JUnit5依赖注入与测试接口
    Python如何设计面向对象的类(下)
    JUnit5参数化测试的几种方式
    JUnit5的条件测试、嵌套测试、重复测试
    熬夜肝了一份 C++/Linux 开发学习路线
    适合普通大学生的 Java 后端开发学习路线
    二本,拿腾讯,阿里 offer 了
    适合普通大学生的前端学习路线
    41道计算机网络高频面试题(附带答案)
    在Rancher中修改K8S服务参数的万金油法则
  • 原文地址:https://www.cnblogs.com/lvyerose/p/5333241.html
Copyright © 2011-2022 走看看