自动生成versionCode/VersionName
来源:互联网 发布:淘宝在线云客服门户 编辑:程序博客网 时间:2024/05/22 15:35
使用Gradle自动化生成VersionCode与VersionName,使用VersionName与git版本库关联,并且区分开发版本与发布版本的解决方案。
详情请看文章:
http://my.oschina.net/mengshuai/blog/551356
第[1]段代码
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
def getVersionCode = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--all', '--count'
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())+400
}
catch (ignored) {
return -1;
}
}
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--dirty'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return null;
}
}
android {
compileSdkVersion = 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.a.b.c"
minSdkVersion 14
targetSdkVersion 21
multiDexEnabled true
versionCode getVersionCode()
versionName getVersionName()
}
signingConfigs {
release {
storeFile file("anl.keystore")
storePassword "*****"
keyAlias "***** "
keyPassword "***** "
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
applicationIdSuffix 'debug'
versionNameSuffix '-debug'
}
}
compileSdkVersion 21
productFlavors {
}
dexOptions{
incremental true
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
compile fileTree(include: '*jar', dir: 'libs')
compile project(':qavlib')
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
compile 'com.squareup:otto:+'
compile 'com.github.anrwatchdog:anrwatchdog:1.1.+'
compile 'com.alibaba:fastjson:+'
}
详情请看文章:
http://my.oschina.net/mengshuai/blog/551356
第[1]段代码
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
def getVersionCode = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--all', '--count'
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())+400
}
catch (ignored) {
return -1;
}
}
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--dirty'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return null;
}
}
android {
compileSdkVersion = 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.a.b.c"
minSdkVersion 14
targetSdkVersion 21
multiDexEnabled true
versionCode getVersionCode()
versionName getVersionName()
}
signingConfigs {
release {
storeFile file("anl.keystore")
storePassword "*****"
keyAlias "***** "
keyPassword "***** "
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
applicationIdSuffix 'debug'
versionNameSuffix '-debug'
}
}
compileSdkVersion 21
productFlavors {
}
dexOptions{
incremental true
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
compile fileTree(include: '*jar', dir: 'libs')
compile project(':qavlib')
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
compile 'com.squareup:otto:+'
compile 'com.github.anrwatchdog:anrwatchdog:1.1.+'
compile 'com.alibaba:fastjson:+'
}
0 0
- 自动生成versionCode/VersionName
- gradle下,自动关联versionName,versionCode
- 如果通过Gradle自动生成各个brand的versionName和VersionCode
- VersionCode和VersionName
- Android版本号versionCode,versionName
- VersionCode和VersionName
- VersionCode和VersionName相关
- AndroidManifest:VersionCode和VersionName
- AndroidManifest:VersionCode和VersionName
- Android versionCode与versionName
- versionCode和versionName
- VersionCode和VersionName
- AndroidManifest:VersionCode和VersionName
- Android versionCode与versionName
- VersionCode与VersionName
- Android 应用程序版本(versionCode, versionName)
- Android 应用程序版本(versionCode, versionName)
- Android 应用程序版本(versionCode, versionName)
- RANSAC随机抽样一致算法
- 十分钟用jQuery编写treelist树形目录折叠插件
- 扩展系统功能--装饰模式(Decorator)
- 从开始到现在
- 码农改代码
- 自动生成versionCode/VersionName
- java数学精确运算—BigDecimal()类
- C++的四种cast操作符的区别--类型转换
- Django:Django安装
- hdu 1003
- HDU 2089 不要62 (数位DP)
- java中String的API使用方法
- pthread线程取消示例
- 特征匹配及其优化