参考github上的demo,新建一个project后,会有一个位于app文件夹下的局部build.gradle文件和一个位于根目录project下的全局build.gradle文件,我们要修改的是局部gradle文件:
1 buildscript { 2 repositories { 3 mavenCentral() 4 } 5 dependencies { 6 // replace with the current version of the Android plugin 7 classpath 'com.android.tools.build:gradle:1.0.0' 8 // the latest version of the android-apt plugin 9 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' 10 } 11 } 12 13 repositories { 14 mavenCentral() 15 mavenLocal() 16 } 17 18 apply plugin: 'com.android.application' 19 apply plugin: 'android-apt' 20 def AAVersion = '3.3-SNAPSHOT' // change this to your desired version, for example the latest stable: 3.2 21 22 dependencies { 23 apt "org.androidannotations:androidannotations:$AAVersion" 24 compile "org.androidannotations:androidannotations-api:$AAVersion" 25 } 26 27 apt { 28 arguments { 29 androidManifestFile variant.outputs[0].processResources.manifestFile 30 // if you have multiple outputs (when using splits), you may want to have other index than 0 31 32 resourcePackageName 'org.androidannotations.gradle' 33 34 // If you're using Android NBS flavors you should use the following line instead of hard-coded packageName 35 // resourcePackageName android.defaultConfig.packageName 36 37 // You can set optional annotation processing options here, like these commented options: 38 // logLevel 'INFO' 39 // logFile '/var/log/aa.log' 40 } 41 } 42 43 android { 44 compileSdkVersion 19 45 buildToolsVersion "21.1.1" 46 47 defaultConfig { 48 minSdkVersion 9 49 targetSdkVersion 19 50 } 51 }
最后再在AndroidManifest.xml中的Activity的名字后面加上 _(下划线)
然后编译项目 完成! 如果报错,请多编译几次。编译按钮:
我的顺利编译通过。 参考博客:http://blog.csdn.net/ljphhj/article/details/37601173