android studio 框架搭建:加入注解框架Annotations


參考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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM