最近因?yàn)楣卷?xiàng)目有些功能上的改動(dòng),可以說(shuō)是一個(gè)周期挺長(zhǎng)的迭代??墒菃?wèn)題在于現(xiàn)在使用的項(xiàng)目代碼是基于MVC模式的,邏輯嵌套搞的像一張蜘蛛網(wǎng)一樣。也沒(méi)有像樣的思維導(dǎo)圖什么的,只能自己看代碼理清邏輯在修改。作為后面才來(lái)公司的員工,對(duì)于之前的架構(gòu)我已無(wú)力吐槽,只想完成任務(wù)事大。
但是在下班之余,我還是想自己重構(gòu)一遍整個(gè)項(xiàng)目,從頭開(kāi)始自己寫(xiě)一遍所有的代碼。由于項(xiàng)目也不算小,所以愛(ài)偷懶的我想到了用什么框架來(lái)加快速度。然后很自然的我選擇了安卓開(kāi)發(fā)框架中鶴立雞群的androidannotations。說(shuō)實(shí)在的,我用的是android
studio,剛開(kāi)始配置時(shí)就遇到了很多問(wèn)題。網(wǎng)上看到了很多關(guān)于AS上配置AA的方法,事實(shí)也證明是可行的。但是去官網(wǎng)看一下,不難發(fā)現(xiàn)現(xiàn)在的最新版本是4.2.0。而網(wǎng)上大多是些以前老版本的配置,這又讓我這種有強(qiáng)迫癥的同學(xué)難受了。于是本著死磕的精神,我稍稍研究了一下,也是第一次在簡(jiǎn)書(shū)上記錄一下初學(xué)AA框架的配置過(guò)程,其中有些問(wèn)題雖然簡(jiǎn)單,但是剛開(kāi)始遇到,還是花費(fèi)了很多的精力去解決。記錄分享一下,望以后自己能多多改進(jìn)。
我配置好的4.2.0版的項(xiàng)目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 {
//這里是指定遠(yuǎn)程倉(cāng)庫(kù),雖然我不知道那是個(gè)什么樣的,但是按照官方要求的就這么配吧!
repositories {
mavenCentral()
}
//這應(yīng)該的些依賴(lài)庫(kù)
dependencies {
// replace with the current version of the Android plugin
// 版本號(hào)與根目錄下 build.gradle 中所依賴(lài)的版本號(hào)一致
classpath'com.android.tools.build:gradle:2.2.2'
// the latest version of the android-apt plugin
//這的話就是要寫(xiě)最新的版本號(hào)吧,當(dāng)然如果版本號(hào)不對(duì)應(yīng)是配置不好的。不信你改成1.4試試。反正我改了就報(bào)錯(cuò)
classpath'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
repositories {
mavenCentral()
mavenLocal()
}
//這里是添加依賴(lài)插件,定義版本號(hào)
applyplugin:'android-apt'
defAAVersion ='4.2.0'
//這里好像是些具體的依賴(lài),我也說(shuō)不上來(lái),但是還不能少
dependencies {
apt"org.androidannotations:androidannotations:$AAVersion"
compile"org.androidannotations:androidannotations-api:$AAVersion"
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
}
}
配置好了以后開(kāi)始使用,很多的注解標(biāo)簽確實(shí)給人感覺(jué)上方便很多,但是我還是遇到了一個(gè)坑。就是
一個(gè)控件如果使用了@ViewById初始化,那么在使用控件添加的方法不能是私有的,也就是平時(shí)習(xí)慣了定義方法的時(shí)候?qū)憄rivate到這里就不行了,會(huì)報(bào)錯(cuò)。最好改成public。
我想以后還會(huì)有更多的坑等著我,但是我也相信,坑進(jìn)多了,也就習(xí)慣了。不怕,與奮斗中的同學(xué)們共勉。