Android Annotations环境搭建(Android Studio)

1.下载Annotations 戳我

2.创建一个新的APP

3.Annontations目录如下:


复制第一个文件夹(AndroidAnnotations)到刚刚创建的项目的lib文件夹下


4.配置文件

在左侧切换至Project的Porject模式,方便我们查看项目的目录


注意右图里的有2个build.gradle文件,一个局部有效,一个全局有效,在局部build.gradle中(加入红色字体

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion='3.3.2'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.bq.facecode"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'

    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

apt {
    arguments {
        //老版本的写法2.2.1以前
        //androidManifestFile variant.processResources.manifestFile
        //2.2.1以后
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName 'com.bq.facecode'//项目包名
    }
}
然后在全局build.gradle中加入

// 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.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

需要注意的地方是,gradle的版本会造成一个错误

No such property 'processResources' on  com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated

遇到这个问题请不要慌张,查看一下全局文件中的红色字体部分,是不是使用的

com.neenbedankt.gradle.plugins:android-apt:1.3,如果是可以改成1.4试试


再查看一下你的gradle的版本,如果版本低于2.2.1,可能你得在局部文件中使用

androidManifestFile variant.processResources.manifestFile //(低版本的写法)

androidManifestFile variant.outputs[0].processResources.manifestFile //(高版本的写法)


关于查看项目Gradle的版本:

在项目左侧文件夹中找到gradle->wrapper->gradle-wrapper.properties,打开后即可看到

#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
红字那里就是你当前使用的版本

5.最后修改manifest文件

在Activity最后添加一个下划线“—”


6.开始测试~


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值