第一 先在局部添加依赖 为 //*****注释的都要加进去
apply plugin: 'android-apt' //*****
def AAVersion = '3.1' //*****
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.admin.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'org.androidannotations:androidannotations:4.0.0' //*****
apt "org.androidannotations:androidannotations:$AAVersion" //***** 添加依赖
compile "org.androidannotations:androidannotations-api:$AAVersion" //*****
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile //*****
}
}
第二 在全局添加 也是有//****** 注释 必须要的
// 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:2.0.0'
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()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
第三
3.1 到 AndroidManifest.xml里面在要用的相关activity后面加"_" 如MainActivity_
<activity android:name=".ui.MainActivity_" /> //MainActivity_还没有编译之前是红色的
3.2 到Activity 前面加上
@EActivity public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}
第四 编译一下,如果没有报错,AndroidManifest.xml里面的红色MainActivity_就变成正常代码的颜色了,这样就可以使用框架了