AndroidStudio1.1.0配置使用androidannotations
1:从GitHub上下载最新版androidannotations-api-3.3.1.jar
2:新建Module:my-aa-test
3:将androidannotations-api-3.3.1.jar拷贝到模块libs目录下面
4:修改工程下面的build.gradle配置文件内容:
主要增加了以下配置项:
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
// 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.0.0' //aa配置1 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } }
5:修改模块my-aa-test下的build.gradle配置文件内容:
apply plugin: 'com.android.application' //aa配置 apply plugin: 'android-apt' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.example.y.myapplication" minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } //aa配置 apt { arguments { androidManifestFile variant.outputs[0].processResources.manifestFile resourcePackageName "com.example.y.myapplication"//应用包名 } } dependencies { //aa配置 apt 'org.androidannotations:androidannotations:3.3.1' compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.3' }
6:把androidannotations-api-3.3.1.jar加载进来,鼠标右键"add as library ":
此时模块中的build.gradle配置文件中会多出以下配置项:
compile files('libs/androidannotations-api-3.3.1.jar')
7:修改MainActivity,对其进行注解
@EActivity(R.layout.activity_main) public class MainActivity extends ActionBarActivity { }
8:修改AndroidManifest.xml配置文件把MainActivity修改为MainActivity_
<activity android:name=".MainActivity_" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
9:运行测试,会弹出编辑框提示,直接点击"Run"进行运行,继续点击"Continue Anyway",等待Gradle进行打包处理,最后测试通过.