android studio 配置androidannotations注入框架,問題一二三

最近比較閒,老是感覺編碼應該是項輕鬆的感覺,代碼不應該繁複!好的代碼應該是易於理解,易讀的,但是鑑於在同一個團隊中各個人的水平不一樣,然後代碼風格也不一樣,導致每次改代碼修BUG的時候就莫名的煩躁,然後就萌生了依賴注入這麼個東西,我瞅了半天,好像這個還不錯,就試試用下!

     閒話少說,開始配置!比較操蛋,一開始配這個東西有點兒蒙圈,百度的都不知道是寫什麼東西!自己摸索算是弄出來了

    1.https://github.com/excilys/androidannotations/wiki/Building-Project-Gradle

這是項目配置地址!按照步驟來,注意絕壁不能省略每一步啊,不然的話就只出xml佈局,而且還不是你自己的

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.zy"
        minSdkVersion 15
        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'])
    compile 'com.android.support:appcompat-v7:23.2.0'
    //依賴注入
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
    }
}


這個是你自己的項目配置地址,紅色的一定要配置進去,不然你在AndroidManifest.xml配置你的Activity會報錯的


// 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'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
這個是你工作空間的Gradle,這個加上



注意引用的類要加上下劃線,如果沒加,控制檯會提示的


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章