Coding时常常会用到一些support包或其它的依赖包等,有时候也建立一些Library,这些support包和依赖包,Library中的包如何更好的配置版本呢?若是须要修改版本,怎么办?每次都手动修改,修改完以后,在 Sync Now 接着Gradle再编译半天?其实用不着那么麻烦就能很好的管理项目中的版本。首先在工程最外层的gradle.properties中以下定义:java
# compileSdkVersion
COMPILE_SDK_VERSION=24
# buildToolsVersion
BUILD_TOOLS_VERSION=25.0.2
# minSdkVersion
MIN_SDK_VERSION=16
# targetSdkVersion
TARGET_SDK_VERSION=25
# support_v7
SUPPORT_V7_VERSION=24.1.1
# 当前发布版本versionCode
VERSION_CODE=1
# 当前发布版本versionName
VERSION_NAME=1.0.0
其次在应用 app 中或者那些建立的库 Library 中的 build.gradle 中以下修改,对号入座。版本号为整数时后面须要声明类型as int
默认为String
。android
apply plugin: 'com.android.application'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
applicationId "com.common.app"
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// support-v7包版本,注意两边是 " "
compile "com.android.support:appcompat-v7:${SUPPORT_V7_VERSION}"
}
到此收工!!!web
本文分享 CSDN - 秦川小将。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。app