android开发:gradle版本统一配置


 compileSdkVersion 29
    buildToolsVersion '29.0.2'

    defaultConfig {
        applicationId "com.phyplusinc.android.phymeshprovisioner"
        minSdkVersion 18
        targetSdkVersion 29
        versionCode 10305   // 01.03.05
        versionName "1.1.1 - Internal - 1.3.5"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true


  implementation 'com.android.support:appcompat-v7:28.0.0'
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'

以前我们依赖第三方库和SDK是这样直接声明版本号的,但是多人开发下这样引入依赖容易出现冲突:假如每个模块的SDK版本号都不一样,或者俩个模块都依赖了同个第三方库,但是版本不同,那程序可能就会出现各种冲突,因此需要对项目进行版本统一配置。

1.在项目的根目录下创建version.gradle

/**
 * 统一SDK版本
 */
def BUILD_VERSIONS = [:]
BUILD_VERSIONS.MIN_SDK = 21
BUILD_VERSIONS.TARGET_SDK = 28
BUILD_VERSIONS.COMPILE_SDK = 28
BUILD_VERSIONS.BUILD_TOOLS = "29.0.1"
BUILD_VERSIONS.VERSION_CODE = 1
BUILD_VERSIONS.VERSION_NAME = "1.1.0"
ext.BUILD_VERSIONS = BUILD_VERSIONS

/**
 * 统一第三方库版本号版本
 */
def versions = [:]
versions.easypermissions = "1.0.1"
versions.bluetooth = "1.4.0"

/**
 * 根据上面的版本号依赖第三方库
 */
def support = [:]
support.easypermissions = "pub.devrel:easypermissions:$versions.easypermissions"
support.bluetooth = "com.inuker.bluetooth:library:$versions.bluetooth"
ext.support = support

2.在项目的build.gradle中添加


buildscript {
	//添加依赖
    apply from: 'version.gradle'
 }

3.在app的build.gradle中引入依赖

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion BUILD_VERSIONS.COMPILE_SDK
    defaultConfig {
    	//依赖SDK
        applicationId "com.skyworth.car.rulerdemo"
        minSdkVersion BUILD_VERSIONS.MIN_SDK
        targetSdkVersion BUILD_VERSIONS.TARGET_SDK
        versionCode BUILD_VERSIONS.VERSION_CODE
        versionName  BUILD_VERSIONS.VERSION_NAME
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
   //依赖第三方库
    api support.bluetooth
    api support.easypermissions
}
repositories {
    mavenCentral()
}

哪个模块需要蓝牙则调用 api support.bluetooth,需要动态权限则调用api support.easypermissions,而且SDK版本号我们也进行了统一。

发布了194 篇原创文章 · 获赞 42 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_39027256/article/details/103604219
今日推荐