Android Annotations框架配置Android Studio的操作步驟
1.配置gradle(Project):
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
allprojects {
repositories {
mavenCentral()
mavenLocal()
maven {
url 'https://repo.spring.io/libs-snapshot'
}
}
}
2.配置gradle(app):
新增:
apply plugin: 'android-apt'
def AAVersion = '版本號'
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 "com.example.hp.myapplication"
// You can set optional annotation processing options here, like these commented options:
// logLevel 'INFO'
// logFile '/var/log/aa.log'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}
到這裡位置已經可以正常使用AndroidAnnotations,包括 @EActiivty 等.
(注意:在使用過註解工具之後點選Build中的Make Project,
後臺會自動生成一個比類名多一個下劃線的類,比如:MainActivity生成之後就是MainActivity_,
這時候去MainFests中把android: name=“ "類名"中的類名後加上"_"點選Make Project就行了)
要是使用網路Rest註解工具在gradle(app)中新增:
//新增的是為了防止重複引用
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
//新增的是第三方包
dependencies {
apt "org.androidannotations:rest-spring:$AAVersion"
compile "org.androidannotations:rest-spring-api:$AAVersion"
compile 'org.springframework.android:spring-android-rest-template:2.0.0.BUILD-SNAPSHOT'
compile 'org.springframework.android:spring-android-core:2.0.0.BUILD-SNAPSHOT'
compile files('libs/jackson-annotations-2.8.0-20160517.060412-45.jar')
compile files('libs/jackson-core-2.8.0-20160515.013135-115.jar')
compile files('libs/jackson-databind-2.8.0-20160517.061118-256.jar')
}