Android Studio中统一管理版本号引用配置

// 目标版本

TARGET_SDK_VERSION = 23

// 设置是否使用混淆

MINIFY_ENABLED = true

MINIFY_DISABLED = false

// 应用程序包名

APPLICATION_ID = ‘com.mainiway.eworkpal’

// Version of “com.android.support:appcompat-v7”, refer it as folow:

// compile “com.android.support:appcompat-v7:${APPCOMPAT_VERSION}”

APPCOMPAT_VERSION = ‘23.2.1’

}

**4.**在app目录下的build.gradle中使用

dependencies {

compile fileTree(include: [‘*.jar’], dir: ‘libs’)

compile “com.android.support:cardview-v7:${APPCOMPAT_VERSION}”

compile “com.android.support:appcompat-v7:${APPCOMPAT_VERSION}”

compile “com.android.support:design:${APPCOMPAT_VERSION}”

compile ‘com.github.bumptech.glide:glide:3.7.0’

}

方式二(推荐)

**1.**在根目录下的build.gradle文件下添加 ext{ … } 中的内容

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

buildscript {

repositories {

jcenter()

}

dependencies {

classpath ‘com.android.tools.build:gradle:2.2.3’

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

}

}

allprojects {

repositories {

jcenter()

maven { url “https://jitpack.io” }

}

}

task clean(type: Delete) {

delete rootProject.buildDir

}

// Define versions in a single place

ext {

// SDK And Tools

minSdkVersion = 14

targetSdkVersion = 23

compileSdkVersion = 23

buildToolsVersion = ‘24.0.2’

//Dependencies

supportLibraryVersion = ‘23.2.1’

}

**2.**在app目录下build.gradle中使用 $rootProject.supportLibraryVersion

apply plugin: ‘com.android.application’

android {

compileSdkVersion rootProject.ext.compileSdkVersion

buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {

applicationId ‘com.mainiway.demo’

minSdkVersion rootProject.ext.minSdkVersion

targetSdkVersion rootProject.ext.targetSdkVersion

versionCode 1

versionName “1.0.0”

}

}

dependencies {

compile fileTree(include: [‘*.jar’], dir: ‘libs’)

compile “com.android.support:cardview-v7:$rootProject.supportLibraryVersion”

compile “com.android.support:appcompat-v7:$rootProject.supportLibraryVersion”

compile “com.android.support:design:$rootProject.supportLibraryVersion”

}

方式三(推荐)

也可以在根目录下的 build.gradle 文件中声明 ext{ … }  时, 加上一个变量 var ,如:

ext {

var = [

// SDK And Tools

minSdkVersion : 14,

targetSdkVersion : 25,

compileSdkVersion : 25,

buildToolsVersion : “25.0.2”,

versionName : “1.0.0”,

//Dependencies

supportLibraryVersion: “25.2.0”

]

}

对应的引用方式:

android {

compileSdkVersion var.compileSdkVersion

buildToolsVersion var.buildToolsVersion

defaultConfig {

applicationId “com.xxx.xxx”

minSdkVersion var.minSdkVersion

targetSd
kVersion var.targetSdkVersion

versionCode 1

versionName var.version

}

}

dependencies {

compile “com.android.support:appcompat-v7:$var.supportLibraryVersion”

compile “com.android.support:recyclerview-v7:$var.supportLibraryVersion”

compile “com.android.support:cardview-v7:$var.supportLibraryVersion”

}

或者像这样:

ext {

minSdkVersion: 14,

targetSdkVersion: 25,

compileSdkVersion: 25,

buildToolsVersion: “25.0.2”,

versionName: “1.0.0”,

//Dependencies

supportLibraryVersion: “25.2.0”

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值