[備忘]Android Studio 簡單管理依賴包版本

前言

當一個app存在著很多module,并且module當中又有重復(fù)的依賴引用,10個module可以手動一個個改,那么100個module呢?手動改,那你手就要廢了。

如何統(tǒng)一管理

先看看下面這句代碼,經(jīng)常可以看到其他開源項目中build.gradle有這句引用

apply from: "config.gradle" // 引入該文件,加載root build.gradle當中,所有的module就都可以使用

在根目錄當中創(chuàng)建config.gradle,那么config.gradle當中又哪些內(nèi)容呢,來看一下我的配置清單

//這邊很熟悉吧,不用再解釋
ext {
    android = [
            minSdkVersion    : 15,
            targetSdkVersion : 22,
            compileSdkVersion: 25,
            buildToolsVersion: "25.0.0",
            applicationId    : "com.xxx.app.xxx",//包名
            versionCode      : 3,//版本號
            versionName      : "1.0.2"
    ]
//google的支持包版本
    support=[
            support_version:"25.0.0"
    ]
//其他第三方
    other=[
            retrofit:"2.1.0",
            rxjava:"1.1.7",
            rxandroid:"1.2.1",
            okhttp:"3.3.1",
            butterknife:"7.0.1",
            material_dialogs:"0.9.1.0",
            baseitemlayoutlibrary:"2.1.1",
            gson:"2.2.4",
            recovery:"0.0.8",
            multidex:"1.0.1",
            fragmentation:"0.10.1",
            WheelPicker:"1.2.4"
    ]

}

接著引入該文件,上面已經(jīng)講過了。

使用方式

def support = rootProject.ext.support
def other = rootProject.ext.other
def dev = rootProject.ext.android 拆分一下rootProject//固定的方法,ext 也是固定的方法 ,android 這個就是config.gradle定義的android。
android {
    compileSdkVersion dev.compileSdkVersion  //一一對應(yīng)使用,以下都是類似
    buildToolsVersion dev.buildToolsVersion

    //recommend
    dexOptions {
        jumboMode = true
    }
    defaultConfig {
        applicationId dev.applicationId
        minSdkVersion dev.minSdkVersion
        targetSdkVersion dev.targetSdkVersion
        versionCode dev.versionCode
        versionName dev.versionName
}
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-annotations:' + support.support_version
    compile 'com.android.support:appcompat-v7:' + support.support_version
    compile 'com.android.support:design:' + support.support_version
    compile 'com.android.support:cardview-v7:' + support.support_version
    compile 'com.android.support:recyclerview-v7:' + support.support_version
    compile 'com.squareup.retrofit2:retrofit:' + other.retrofit
    compile 'com.squareup.retrofit2:adapter-rxjava:' + other.retrofit
    compile 'com.squareup.retrofit2:converter-gson:' + other.retrofit
    compile 'io.reactivex:rxjava:' + other.rxjava
    compile 'io.reactivex:rxandroid:' + other.rxandroid
    compile 'com.squareup.okhttp3:okhttp:' + other.okhttp
    compile 'com.squareup.okhttp3:logging-interceptor:' + other.okhttp
    compile 'com.jakewharton:butterknife:' + other.butterknife
    compile 'com.afollestad.material-dialogs:commons:' + other.material_dialogs
    compile 'com.maiml:baseitemlayoutlibrary:' + other.baseitemlayoutlibrary
    compile 'com.android.support:multidex:' + other.multidex
    compile 'me.yokeyword:fragmentation:' + other.fragmentation
}

這樣你所有的module都可以這樣使用來進行版本控制。

小記

這是參考其他同志的寫法,如果你有更好的方式,歡迎幫我提出,記錄在這。以備后用。謝謝

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容