Android annotations 框架

Gradle配置:
Project: build.gradle
只需要在dependencies中加:
classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’
如:

   buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        //下面这一行就是需要加的
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
} 

app: build.gradle**(看注释)**

apply plugin: 'com.android.application'
//下面这两行都要加
apply plugin: 'com.neenbedankt.android-apt'
def AAVersion = '3.0.1' //最新版本号

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.example.baiyuanwei.test"
        minSdkVersion 18
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    //下面这两行也要加
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}
//apt 也是要加的,注意有个“ ?“号
apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
        //com.example.baiyuanwei.test是你的包名
        resourcePackageName "com.example.baiyuanwei.test"
    }
}

坑1:
build会出现此异常;
原因:可能是你添加的依赖有问题;
我的解决方案:就在app:build.gradle中添加apt,如上;

注意:凡是annotations 注解过的自定义view、fragment、activity,在用的时候都要用annotations自动生成的替代类,即”……_” ;
如:TagHotUserShowsView,则其annotations自动生成的类就是TagHotUserShowsView_

踩过的坑:自定义view: TagHotUserShowsView ,此view用annotations注解过,而我用的时候,用的是TagHotUserShowsView,导致我@ViewById结果都是null。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值