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/

posted @ 2014-12-30 15:58  机智大脸喵  阅读(902)  评论(2编辑  收藏  举报