一步一步手撸Android通用框架 (六)

这章主要配置统一版本管理:

  • 在项目根目录新建配置文件config.gradle:
ext {

    android = [
            versionCode        : 1,
            versionName        : '1.0.0',

            compileSdkVersion  : 26,
            buildToolsVersion  : '26.0.2',
            minSdkVersion      : 16,
            targetSdkVersion   : 26,

            supportSdkVersion  : '26.1.0',
            multidexVersion    : '1.0.3',
            utilcodeVersion    : '1.13.1',
            rxjavaSdkVersion   : '2.1.3',
            rxandroidSdkVersion: '2.0.1',
            retrofitSdkVersion : '2.3.0',
            okhttpSdkVersion   : '3.4.1',
            constraintVersion  : '1.0.2',
            glideSdkVersion    : '4.0.0',
    ]

    dependencies = [
            "design"                 : "com.android.support:design:${android["supportSdkVersion"]}",
            "appcompat"              : "com.android.support:appcompat-v7:${android["supportSdkVersion"]}",
            "recyclerview"           : "com.android.support:recyclerview-v7:${android["supportSdkVersion"]}",
            "support-v4"             : "com.android.support:support-v4:${android["supportSdkVersion"]}",
            "multidex"               : "com.android.support:multidex:1.0.3",
            "interceptor"            : "com.squareup.okhttp3:logging-interceptor:${android["okhttpSdkVersion"]}",
            "retrofit"               : "com.squareup.retrofit2:retrofit:${android["retrofitSdkVersion"]}",
            "retrofit-converter-gson": "com.squareup.retrofit2:converter-gson:${android["retrofitSdkVersion"]}",
            "retrofit-adapter-rxjava": "com.squareup.retrofit2:adapter-rxjava2:${android["retrofitSdkVersion"]}",
            "okhttp"                 : "com.squareup.okhttp3:okhttp:${android["okhttpSdkVersion"]}",
            "rxjava"                 : "io.reactivex.rxjava2:rxjava:${android["rxjavaSdkVersion"]}",
            "rxandroid"              : "io.reactivex.rxjava2:rxandroid:${android["rxandroidSdkVersion"]}",
            "javax-annotation"       : "org.glassfish:javax.annotation:10.0-b28",
            "glide"                  : "com.github.bumptech.glide:glide:${android["glideSdkVersion"]}",
            "utilcode"               : "com.blankj:utilcode:${android["utilcodeVersion"]}",
            "constraint-layout"      : "com.android.support.constraint:constraint-layout:${android["constraintVersion"]}",
    ]
}
  • 在项目Gradle文件中引用:
//这里需要应用配置文件。
apply from: "config.gradle"
buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

  • 在需要的地方引用:
apply plugin: 'com.android.library'

android {
    compileSdkVersion rootProject.ext.android["compileSdkVersion"]



    defaultConfig {
        minSdkVersion rootProject.ext.android["minSdkVersion"]
        targetSdkVersion rootProject.ext.android["targetSdkVersion"]
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.blankj:utilcode:1.13.1'
    compile rootProject.ext.dependencies["design"]
    compile rootProject.ext.dependencies["appcompat"]
    compile rootProject.ext.dependencies["support-v4"]
    compile rootProject.ext.dependencies["recyclerview"]
    compile rootProject.ext.dependencies["constraint-layout"]
}

源码地址:https://github.com/zhangzhichaolove/BasicsFrame

    原文作者:有梦想的程序丶猿
    原文地址: https://www.jianshu.com/p/14496b4a024c
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞