搞安卓开发以来,一直使用的Eclipse,Google出了AndroidStudio(简称AS)以后,一直忙于项目没有时间试试,今天装了一个适应一下,然后想在里面用上AndroidAnnotions(简称AA)(一个挺不错的开源框架,用起来特别方便,如果你现在在用Spring的注解,就会想在android中也来这么一个)。配置的时候遇到点问题!!!!!
1.首先,你可以上AndroidAnnotations的官网:http://androidannotations.org/,学习一下如何使用标签;
2.在Eclipse中的配置参考:https://github.com/excilys/androidannotations/wiki/Eclipse-Project-Configuration
下面讲讲如何在AS中配置AA:
1.安装AS,有钱的翻墙,没钱的百度下载AS;
2.建立AS的新项目,在左侧切换至Project的Porject模式,方便我们查看项目的目录
------>
注意右图里的有2个build.gradle文件,一个局部有效,一个全局有效,在局部build.gradle中(加入红色字体)
apply plugin: 'com.android.application' apply plugin: 'android-apt' def AAVersion='3.3.2' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.bq.facecode" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' apt "org.androidannotations:androidannotations:$AAVersion" compile "org.androidannotations:androidannotations-api:$AAVersion" } apt { arguments { //老版本的写法2.2.1以前 //androidManifestFile variant.processResources.manifestFile //2.2.1以后 androidManifestFile variant.outputs[0].processResources.manifestFile resourcePackageName 'com.bq.facecode'//项目包名 } }
然后在全局build.gradle中加入
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
需要注意的地方是,gradle的版本会造成一个错误:
No such property 'processResources' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated
遇到这个问题请不要慌张,查看一下全局文件中的红色字体部分,是不是使用的
com.neenbedankt.gradle.plugins:android-apt:1.3,如果是可以改成1.4试试
再查看一下你的gradle的版本,如果版本低于2.2.1,可能你得在局部文件中使用
androidManifestFile variant.processResources.manifestFile //(低版本的写法)
androidManifestFile variant.outputs[0].processResources.manifestFile //(高版本的写法)
关于查看项目Gradle的版本:
在项目左侧文件夹中找到gradle->wrapper->gradle-wrapper.properties,打开后即可看到
#Wed Oct 21 11:34:03 PDT 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
红字那里就是你当前使用的版本