AndroidStudio 添加 AndroidAnnotations

1、添加对apt的依赖

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.2+‘
    }
}

 2、应用apt插件

apply plugin: ‘android-apt‘

 3、配置apt的参数,将com.example.package.name替换成项目名称

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName "com.example.package.name"
    }
}

 4、添加对androidannotation的依赖

dependencies {
    apt "org.androidannotations:androidannotations:3.0+"          // add these
    compile "org.androidannotations:androidannotations-api:3.0+"  // two lines
    compile ‘com.android.support:appcompat-v7:+‘
    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
}

 5、完整版

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.2+‘
    }
}

apply plugin: ‘android‘
apply plugin: ‘android-apt‘

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.txt‘
        }
    }
}

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName "com.example.package.name"
    }
}

dependencies {
    apt "org.androidannotations:androidannotations:3.0+"
    compile "org.androidannotations:androidannotations-api:3.0+"
    compile ‘com.android.support:appcompat-v7:+‘
    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
}

 来自 http://www.jayway.com/2014/02/21/androidannotations-setup-in-android-studio/

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。