1、build.gradle 需要添加的内容
标注的颜色是新建项目之后,build.gradle文件需要添加的内容。
  1. buildscript {
  2. repositories {
  3. jcenter()
  4. }
  5. dependencies {
  6. classpath 'com.android.tools.build:gradle:1.1.1'
  7. classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
  8. }
  9. }
  10. apply plugin: 'com.android.application'
  11. apply plugin: 'android-apt'
  12. def AAVersion = '3.3.1'
  13. repositories {
  14. jcenter()
  15. }
  16. android {
  17. compileSdkVersion 21
  18. buildToolsVersion "21.1.2"
  19. defaultConfig {
  20. applicationId "com.lpc.test3.app"
  21. minSdkVersion 9
  22. targetSdkVersion 14
  23. versionCode 1
  24. versionName "1.0"
  25. }
  26. compileOptions {
  27. sourceCompatibility JavaVersion.VERSION_1_6
  28. targetCompatibility JavaVersion.VERSION_1_6
  29. }
  30. buildTypes {
  31. release {
  32. minifyEnabled false
  33. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  34. }
  35. }
  36. }
  37. dependencies {
  38. compile fileTree(dir: 'libs', include: ['*.jar'])
  39. compile 'com.android.support:appcompat-v7:22.1.1'
  40. }
  41. dependencies {
  42. apt "org.androidannotations:androidannotations:$AAVersion"
  43. compile "org.androidannotations:androidannotations-api:$AAVersion"
  44. }
  45. apt {
  46. arguments {
  47. androidManifestFile variant.outputs[0].processResources.manifestFile
  48. // if you have multiple outputs (when using splits), you may want to have other index than 0
  49. // If you're using flavors you should use the following line instead of hard-coded packageName
  50. // resourcePackageName android.defaultConfig.packageName
  51. // You can set optional annotation processing options here, like these commented options:
  52. // logLevel 'INFO'
  53. // logFile '/var/log/aa.log'
  54. }
  55. }
2、activity_main内容
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. >
  5. <Button
  6. android:id="@+id/btn1"
  7. android:text="发送通知"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"/>
  10. <Button
  11. android:layout_marginTop="10dp"
  12. android:layout_below="@id/btn1"
  13. android:id="@+id/btn2"
  14. android:text="清除通知"
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"/>
  17. </RelativeLayout>
3、MainActivity 内容
  1. package com.lpc.test3.app;
  2. import android.support.v7.app.ActionBarActivity;
  3. import android.view.View;
  4. import android.widget.Button;
  5. import android.widget.Toast;
  6. import org.androidannotations.annotations.Click;
  7. import org.androidannotations.annotations.EActivity;
  8. import org.androidannotations.annotations.ViewById;
  9. @EActivity(R.layout.activity_main)
  10. public class MainActivity extends ActionBarActivity {
  11. @ViewById
  12. Button btn1;
  13. @ViewById
  14. Button btn2;
  15. @Click
  16. void btn1(View v){
  17. Toast.makeText(MainActivity.this,"大家好",Toast.LENGTH_LONG).show();
  18. }
  19. }

4、最后的运行结果
androidannotations 简单配置-LMLPHP

05-11 09:43