AS使用Android Annotation

来源:互联网 发布:怎么开农村淘宝店 编辑:程序博客网 时间:2024/05/08 15:11

如何在AS中使用最火的框架Android Annotation

目前Android有个很火的框架采用自动注解的方式加载view。我们大家都知道采用反射的方式是非常消耗性能的。但是Annotation官方则申明这种开源框架不但不会消耗性能,相反它还会很大程度上提高性能,大大的降低了维护的成本。提高开发效率是不用讲的了。现在就以这个为起步进行Android开发吧!

1.如何在AS中使用这种开源框架
自从从Eclipse转到AS开发后,就避不开的使用gradle这种构建方式。网上关于gradle的介绍是各种高大上。但是当我第一次使用时真是苦不堪言呀!真是会用了真是感觉他真是太方便了,不会用真是太痛苦了。本文不会介绍gradle的具体使用,如果需要请大家到网上搜索吧!下面就介绍如何在自己的项目中使用这种框架

  • 首先要在全局build.gradle中进行配置需要添加如下的代码如下:
  • dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }

    就是在dependencies节点中添加项目依赖,这样全局gradle就配置完成了。

  • 然后要在项目中gradle进行配置,就是项目最重要的gradle。
    首先在开头添加如下的声明:

apply plugin: 'android-apt'def AAVersion = '3.3.2'

这是声明为apt,后面的版本号根据实际情况进行配置我这里是3.3.2
然后在这个配置文件的dependencies节点中加入如下的配置:

 apt "org.androidannotations:androidannotations:$AAVersion"    compile "org.androidannotations:androidannotations-api:$AAVersion"
  • 最后重要的一点是千万不能忘记在最后配置apt节点这个很重要。配置如下:
  • `apt {
    arguments {
    androidManifestFile variant.outputs[0].processResources.manifestFile
    // if you have multiple outputs (when using splits), you may want to have other index than 0

    // you should set your package name here if you are using different application IDs// resourcePackageName "your.package.name"// You can set optional annotation processing options here, like these commented options:// logLevel 'INFO'// logFile '/var/log/aa.log'

    }
    }`
    这里就大功告成了,这样我们就能使用这个框架了。

1 0
原创粉丝点击