日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android+自定义版本号,Android打包版本号设置方法

發布時間:2024/8/23 Android 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android+自定义版本号,Android打包版本号设置方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

之前沒有設置過打包的命名,每次打包都是默認的"app-realease.apk",之后手動修改名字來顯示出它是一個新版本。

晚上學習了如何配置打包名稱,很簡單,修改build.gradle里的代碼就行。

詳細記錄如下:

1、打開app這個directory下的build.gradle

2、定義打包時間:

//時間

def releaseTime() {

return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))

}

3、自定義發布時的版本號(return的返回值可自行修改,例如1.0、2.0):

//版本號

def getVersionName(){

return "2.0"

}

4、自定義打包名稱(代碼中的XYZ可修改為app名字):

//名稱

applicationVariants.all { variant ->

variant.outputs.each { output ->

def outputFile = output.outputFile

def fileName

if (outputFile != null && outputFile.name.endsWith('.apk')) {

if (variant.buildType.name.equals('release')) {

variant.mergedFlavor.versionName = getVersionName()

fileName = "XYZ_${variant.mergedFlavor.versionName}_release.apk"

} else if (variant.buildType.name.equals('debug')) {

variant.mergedFlavor.versionName = getVersionName()+"."+releaseTime()

fileName = "XYZ_${variant.mergedFlavor.versionName}_debug.apk"

}

output.outputFile = new File(outputFile.parent, fileName)

}

}

}

5、build.gradle的完整代碼:

apply plugin: 'com.android.application'

//定義時間

def releaseTime() {

return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))

}

//設置發布時的版本號

def getVersionName(){

return "2.0"

}

android {

compileSdkVersion 26

buildToolsVersion "26.0.0"

defaultConfig {

applicationId "***"

minSdkVersion 14

targetSdkVersion 23

versionCode 1

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {

release {

buildConfigField("boolean","API_DEBUG","false")

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

debug {

buildConfigField("boolean","API_DEBUG","true")

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

}

//配置打包名稱

applicationVariants.all { variant ->

variant.outputs.each { output ->

def outputFile = output.outputFile

def fileName

if (outputFile != null && outputFile.name.endsWith('.apk')) {

if (variant.buildType.name.equals('release')) {

variant.mergedFlavor.versionName = getVersionName()

fileName = "XYZ_${variant.mergedFlavor.versionName}_release.apk"

} else if (variant.buildType.name.equals('debug')) {

variant.mergedFlavor.versionName = getVersionName()+"."+releaseTime()

fileName = "XYZ_${variant.mergedFlavor.versionName}_debug.apk"

}

output.outputFile = new File(outputFile.parent, fileName)

}

}

}

}

dependencies {

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

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

exclude group: 'com.android.support', module: 'support-annotations'

})

}

總結

以上所述是小編給大家介紹的Android打包版本號設置方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!

總結

以上是生活随笔為你收集整理的android+自定义版本号,Android打包版本号设置方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。