android gradle 版本部队,gradle中统一配置版本的小技巧。

在Project/build.gradle中定义,在module/build.gradle中使用

1、直接在Project/build.gradle中定义和引用:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

ext.compileSdkVersion = 26

ext.targetSdkVersion = 26

ext.support_appcompat_v7 = '26.1.0'

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

}

}

...

数字引用:

compileSdkVersion rootProject.ext.compileSdkVersion

三方库版本号引用:

implementation "com.android.support:appcompat-v7:$support_appcompat_v7"

2、单独在xxx.gradle中定义和引用:

①在Project 层级下新建config.build文件(这里的config可以替换为任何你喜欢的名字),在里面书写配置信息:

ext {//定义所有project公用参数

android = [

compileSdk: 27,

buildTools: "27.0.3",

minSdk    : 19,

minLimitSdk: 19,//限制低版本用户安装

targetSdk : 27,

]

dependencies = [

// App dependencies

junit                : '4.12',

espresso             : '2.2.2',

supportLibraryVersion: '27.1.1',

supportPercentVersion: '25.3.1',

butterknife          : '8.8.1',

gson                 : '2.7',

retrofit             : '2.4.0',

rxjava               : '1.1.6',

rxandroid            : '1.2.1',

loggingInterceptor   : '3.1.0',

stetho               : '1.4.2',

guavaVersion         : '18.0',

leakcanary           : '1.5.4'

]

}

②在Project/build.gradle中引用刚才定义好的config.gradle文件:

apply from: "config.gradle"

③数字引用:

compileSdkVersion rootProject.ext.android.compileSdk

④三方库版本号引用:

api "com.android.support:appcompat-v7:$rootProject.ext.dependencies.supportLibraryVersion"

在Project/gradle.properties中配置,在mudule/build.gradle中使用.

①在Project/gradle.properties中定义:

COMPILE_SDK_VERSON = 26

BUILD_TOOLS_VERSION = 25.0.2

SUPPORTV7_VERSON=25.0.1

②引用到的变量默认是String类型,如果需要in类型,需要在后面添加 as int 声明

compileSdkVersion COMPILE_SDK_VERSON as int

buildToolsVersion BUILD_TOOLS_VERSION

compile "com.android.support:appcompat-v7:${SUPPORTV7_VERSON}"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值