使用 androidannotations 可以从繁琐sb的Android代码中解脱,具体好处可以看官网解说。
1.gradle& android 环境下使用
1.1 首先配置全局的build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
allprojects {
repositories {
jcenter()
}
}
1.2 配置模块build.gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt' // androidannotation添加使用
def AAVersion = '3.3.1' // 版本
//使用 androidannotations 框架 要添加的内容
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
// If you're using flavors you should use the following line instead of hard-coded packageName
// resourcePackageName android.defaultConfig.packageName
// You can set optional annotation processing options here, like these commented options:
// logLevel 'INFO'
// logFile '/var/log/aa.log'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
//添加 androidannotations 框架
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "company.com.mycoding"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
3.注意manifest中activity需要修改成MainActivity_
这样 androidannotations 就可以在项目中使用了,每次run前rebuild即可。