Android Studio3.0 配置AndroidAnnotation注解框架

前言
android学习了一段时间后,想要开发一款App,但是一些复杂的代码写多了实在麻烦,就到网上找了找简便的方法,于是在众多的注解开发框架中,找到了Android Annotation这个框架,这里列出他的一些特点:

(1) 依赖注入:包括 view,extras,系统服务,资源等等。

(2) 简单的线程模型,通过 annotation 表示方法运行在 ui 线程还是后台线程。

(3) 事件绑定:通过 annotation 表示 view 的响应事件,不用在写内部类。

(4) REST 客户端:定义客户端接口,自动生成 REST 请求的实现。

(5) 没有你想象的复杂:AndroidAnnotations 只是在在编译时生成相应子类。

(6) 不影响应用性能:仅 50 kb,在编译时完成,不会对运行时有性能影响。

其他:与 roboguice 的比较:roboguice通过运行时读取 annotations 进行反射,所以可能影响应用性能,而 AndroidAnnotations 在编译时生成子类,所以对性能没有影响。

配置
因为这里使用的是AndroidStudio3.0版本,在网上找到的很多添加依赖包的方法都是在旧版本的AS中使用apt插件进行配置的,而因为Android Studio推出的官方插件annotationProcessor,apt插件的作者已不再更新,所以这里我们就不在讨论apt的配置方法,直接在app的build.gradle中使用annotationProcessor进行配置。

apply plugin: 'com.android.application'
def AAVersion = "4.3.1"
android {
    compileSdkVersion 26
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 26
        // If you have different applicationIds for buildTypes or productFlavors uncomment this block.
        //javaCompileOptions {
        //    annotationProcessorOptions {
        //        arguments = ['resourcePackageName': "org.androidannotations.sample"]
        //    }
        //}
    }
}
 
dependencies {
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    implementation "org.androidannotations:androidannotations-api:$AAVersion"
}                                                                                                                        

转:https://blog.csdn.net/t116180/article/details/80030478

猜你喜欢

转载自www.cnblogs.com/sheseido/p/9788922.html