Android Annotations 4.0.0 配置Rest API
原创
©著作权归作者所有:来自51CTO博客作者陈振阳Plus的原创作品,请联系作者获取转载授权,否则将追究法律责任
AndroidAnnotations 从4.0.0开始模块化了,rest-api作为单独的模块发行。在下面的介绍中有增加一个android annotations模块的方法。
https://github.com/excilys/androidannotations/wiki/Building-Project-Gradle#adding-more-aa-plugins 下面我只说下我的配置:
在项目的build.gradle文件中添加依赖
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
apt "org.androidannotations:rest-spring:$AAVersion"
compile "org.androidannotations:rest-spring-api:$AAVersion"
provided 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
需要依赖Spring For Android。依赖的时候如果用compile,会提示重复引用了Jar包,不加的话,需要的类Android Studio都不提示。所以改成provided了。
需要注意的是,需要在项目的build.gradle和app的build.gralde里同时添加
maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots'
}
开始只在项目的build.gralde里添加的,一直编译不了。后来在app的build.gradle也加上就编译通过了。