美文网首页Android知识
androidannotations初体验

androidannotations初体验

作者: 海贼灰太狼 | 来源:发表于2017-03-08 21:28 被阅读0次

最近因为公司项目有些功能上的改动,可以说是一个周期挺长的迭代。可是问题在于现在使用的项目代码是基于MVC模式的,逻辑嵌套搞的像一张蜘蛛网一样。也没有像样的思维导图什么的,只能自己看代码理清逻辑在修改。作为后面才来公司的员工,对于之前的架构我已无力吐槽,只想完成任务事大。

但是在下班之余,我还是想自己重构一遍整个项目,从头开始自己写一遍所有的代码。由于项目也不算小,所以爱偷懒的我想到了用什么框架来加快速度。然后很自然的我选择了安卓开发框架中鹤立鸡群的androidannotations。说实在的,我用的是android

studio,刚开始配置时就遇到了很多问题。网上看到了很多关于AS上配置AA的方法,事实也证明是可行的。但是去官网看一下,不难发现现在的最新版本是4.2.0。而网上大多是些以前老版本的配置,这又让我这种有强迫症的同学难受了。于是本着死磕的精神,我稍稍研究了一下,也是第一次在简书上记录一下初学AA框架的配置过程,其中有些问题虽然简单,但是刚开始遇到,还是花费了很多的精力去解决。记录分享一下,望以后自己能多多改进。

我配置好的4.2.0版的项目Build.gradle文件是这样的:

applyplugin:'com.android.application'

android {

compileSdkVersion24

buildToolsVersion"24.0.2"

defaultConfig {

applicationId"com.example.administrator.fendou"

minSdkVersion15

targetSdkVersion24

versionCode1

versionName"1.0"

testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {

release {

minifyEnabledfalse

proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'

}

}

}

dependencies {

compile fileTree(dir:'libs',include: ['*.jar'])

compile'com.android.support:design:24.2.0'

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

excludegroup:'com.android.support',module:'support-annotations'

})

compile'com.android.support:appcompat-v7:24.2.0'

testCompile'junit:junit:4.12'

compile'com.github.rey5137:material:1.1.0'

compile'de.greenrobot:eventbus:2.4.0'

compile'net.steamcrafted:load-toast:1.0.6'

}

buildscript {

//这里是指定远程仓库,虽然我不知道那是个什么样的,但是按照官方要求的就这么配吧!

repositories {

mavenCentral()

}

//这应该的些依赖库

dependencies {

// replace with the current version of the Android plugin

// 版本号与根目录下 build.gradle 中所依赖的版本号一致

classpath'com.android.tools.build:gradle:2.2.2'

// the latest version of the android-apt plugin

//这的话就是要写最新的版本号吧,当然如果版本号不对应是配置不好的。不信你改成1.4试试。反正我改了就报错

classpath'com.neenbedankt.gradle.plugins:android-apt:1.8'

}

}

repositories {

mavenCentral()

mavenLocal()

}

//这里是添加依赖插件,定义版本号

applyplugin:'android-apt'

defAAVersion ='4.2.0'

//这里好像是些具体的依赖,我也说不上来,但是还不能少

dependencies {

apt"org.androidannotations:androidannotations:$AAVersion"

compile"org.androidannotations:androidannotations-api:$AAVersion"

}

apt {

arguments {

androidManifestFile variant.outputs[0].processResources.manifestFile

}

}

配置好了以后开始使用,很多的注解标签确实给人感觉上方便很多,但是我还是遇到了一个坑。就是

一个控件如果使用了@ViewById初始化,那么在使用控件添加的方法不能是私有的,也就是平时习惯了定义方法的时候写private到这里就不行了,会报错。最好改成public。

我想以后还会有更多的坑等着我,但是我也相信,坑进多了,也就习惯了。不怕,与奋斗中的同学们共勉。

相关文章

  • androidannotations初体验

    最近因为公司项目有些功能上的改动,可以说是一个周期挺长的迭代。可是问题在于现在使用的项目代码是基于MVC模式的,逻...

  • AndroidAnnotations--依赖注入

    主页: http://androidannotations.org/ AndroidAnnotations的优点1...

  • 注解库汇总

    一、androidannotations 依赖注入(Dependency injection): 支持view, ...

  • Annotation

    https://github.com/excilys/androidannotations/wiki/Enhanc...

  • AndroidAnnotations简介

    AndroidAnnotations(下简称AA)是一个可以提高开发速度的开源框架。如同Spring一样,AA致力...

  • AndroidAnnotations使用

    1.Activity注解@EActivity @EActivity(R.layout.activity_login...

  • 单元测试

    https://github.com/excilys/androidannotations/wiki/Unit-t...

  • 集成Android常用注解

    Butterknife Butterknife,简单用过但是不是很喜欢 AndroidAnnotations 最开...

  • AndroidAnnotations 与 kotlin

    kotlin是谷歌推荐的开发安卓语言,最近由于公司没有什么事情,于是开始想尝试接入新的语言 话不多说,开始接入 下...

  • AndroidAnnotations开源框架

    此框架是快速开发的框架,可以大大提高我们编写代码的速率,所以也被大家称为懒人框架,当然类似被称为懒人框架的开源框架...

网友评论

    本文标题:androidannotations初体验

    本文链接:https://www.haomeiwen.com/subject/caligttx.html