Android_config.gradle_統一配置項目依賴庫版本_筆記

項目中修改config.gradle,各個引用的模塊便可以自動生效,保持gradle引用庫版本的一致,有助於項目模塊化開發。

創建config.gradle文件:

文件內容:

ext {
    plugins = [library    : 'com.android.library',
               application: 'com.android.application',
               maven      : 'com.github.dcendents.android-maven',
               bintray    : 'com.jfrog.bintray']

    android = [applicationId            : "com.***.***",
               compileSdkVersion        : 29,
               buildToolsVersion        : "27.0.3",
               minSdkVersion            : 19,
               targetSdkVersion         : 29,
               testInstrumentationRunner: "androidx.test.runner.AndroidJUnitRunner",

               librayMinSdkVersion      : 19,
               libraryTargetSdkVersion  : 29,

               versionCode              : 1,
               versionName              : "V1.0.1",]

    dependencies = [junit                        : 'junit:junit:4.12',
                    expressoCore                 : 'androidx.test.espresso:espresso-core:3.2.0',
                    appCompat                    : 'androidx.appcompat:appcompat:1.1.0',
                    constraintlayout             : 'androidx.constraintlayout:constraintlayout:1.1.3',
                    //okhttp----nohttp
                    nohttp                       : 'com.yanzhenjie.nohttp:nohttp:1.1.11',
                    okhttp                       : 'com.yanzhenjie.nohttp:okhttp:1.1.11',
                    //Baserecyclerview,列表
                    BaseRecyclerViewAdapterHelper: 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.49-androidx',
                    //fastjson
                    fastjson                     : 'com.alibaba:fastjson:1.1.68.android',
                    //androidx版本,支持android 10,永久維護,EasyPhotos,拍照,從相冊取照片
                    EasyPhotos                   : 'com.github.HuanTanSheng:EasyPhotos:3.0.3',
                    //資源壓縮
                    silicompressor               : 'com.iceteck.silicompressorr:silicompressor:2.2.2',
                    //各種圖表,MPAndroidChart
                    MPAndroidChart               : 'com.github.PhilJay:MPAndroidChart:v3.1.0',
                    //glide,圖片加載
                    glide                        : 'com.github.bumptech.glide:glide:4.10.0',
                    //處理代碼混淆
                    multidex                     : 'com.android.support:multidex:1.0.3',
                    //butterknife,插件
                    butterKnife                  : 'com.jakewharton:butterknife:8.2.0',
                    butterKnifeCompiler          : 'com.jakewharton:butterknife-compiler:8.2.0',
                    //特別效果輸入框
                    material                     : 'com.google.android.material:material:1.0.0']
}

使用:

首先需要在項目的grad了文件中添加聲明

apply from: "config.gradle"

 

module中的使用

apply plugin: rootProject.ext.plugins.application

android {
    compileSdkVersion rootProject.ext.android.compileSdkVersion
    defaultConfig {
        applicationId rootProject.ext.android.applicationId
        minSdkVersion rootProject.ext.android.minSdkVersion
        targetSdkVersion rootProject.ext.android.targetSdkVersion
        versionCode rootProject.ext.android.versionCode
        versionName rootProject.ext.android.versionName
        testInstrumentationRunner rootProject.ext.android.testInstrumentationRunner
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation rootProject.ext.dependencies.appCompat
    implementation rootProject.ext.dependencies.constraintlayout
    testImplementation rootProject.ext.dependencies.junit
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation rootProject.ext.dependencies.expressoCore
    implementation rootProject.ext.dependencies.material
    implementation rootProject.ext.dependencies.butterKnife
    annotationProcessor rootProject.ext.dependencies.butterKnifeCompiler
    implementation rootProject.ext.dependencies.multidex
    implementation rootProject.ext.dependencies.nohttp
    implementation rootProject.ext.dependencies.okhttp
    implementation rootProject.ext.dependencies.fastjson
    implementation rootProject.ext.dependencies.EasyPhotos
    implementation(rootProject.ext.dependencies.glide) {
        exclude group: "com.android.support"
    }
    implementation rootProject.ext.dependencies.BaseRecyclerViewAdapterHelper
    implementation rootProject.ext.dependencies.MPAndroidChart
    implementation rootProject.ext.dependencies.silicompressor
}

 

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