[工控机监控]增加打包信息
This commit is contained in:
@@ -2,6 +2,18 @@ import java.text.SimpleDateFormat
|
|||||||
|
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
|
// 定义当前gradle文件的全局变量
|
||||||
|
ext {
|
||||||
|
//主版本号
|
||||||
|
MAJOR_VERSION = 1
|
||||||
|
//次版本号
|
||||||
|
MINOR_VERSION = 0
|
||||||
|
createFile()
|
||||||
|
buildTimes = getBuildTime()
|
||||||
|
isRelease = checkRelease()
|
||||||
|
gitBranchName = getWorkingBranchName()
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
@@ -9,8 +21,8 @@ android {
|
|||||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
versionCode 1
|
versionCode increasedVersionCode()
|
||||||
versionName "1.0"
|
versionName increasedVersionName()
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
flavorDimensions "multi_device"
|
flavorDimensions "multi_device"
|
||||||
|
|
||||||
@@ -42,14 +54,46 @@ android {
|
|||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//配置自定义打包名称
|
||||||
|
applicationVariants.all { variant ->
|
||||||
|
def buildTypeName = variant.buildType.name
|
||||||
|
//println("buildTypeName-------->" + buildTypeName)
|
||||||
|
variant.outputs.all {
|
||||||
|
StringBuffer buffer = new StringBuffer()
|
||||||
|
buffer.append(getProject().name)
|
||||||
|
buffer.append("_")
|
||||||
|
buffer.append(defaultConfig.versionName)
|
||||||
|
buffer.append(".")
|
||||||
|
buffer.append(buildTimes)
|
||||||
|
buffer.append("_")
|
||||||
|
buffer.append(gitBranchName)
|
||||||
|
buffer.append("_")
|
||||||
|
//获取渠道编号
|
||||||
|
String flavor = variant.flavorName
|
||||||
|
if (flavor != null && flavor != "") {
|
||||||
|
buffer.append(flavor)
|
||||||
|
buffer.append("_")
|
||||||
|
}
|
||||||
|
//获取打包时间
|
||||||
|
def fileName = "${buffer.toString()}${buildTypeName}.apk"
|
||||||
|
//测试文件名称
|
||||||
|
buildConfigField 'String', 'APK_NAME', "\"${fileName}\""
|
||||||
|
//println("fileName-------->" + fileName)
|
||||||
|
//这里修改apk文件名
|
||||||
|
outputFileName = fileName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//插入构建时间
|
//插入构建时间
|
||||||
buildTypes.each {
|
buildTypes.each {
|
||||||
//设置时间格式
|
it.buildConfigField 'String', 'BUILD_TIME', "\"${buildTimes}\""
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd.HHmmss", Locale.getDefault())
|
it.buildConfigField 'String', 'GIT_BRANCH_NAME', "\"${gitBranchName}\""
|
||||||
//获取当前时间
|
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_TAXI', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_P);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
||||||
Date curDate = new Date(System.currentTimeMillis())
|
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_BUS', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_N);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
||||||
String buildTime = formatter.format(curDate)
|
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_M1', 'null'
|
||||||
it.buildConfigField 'String', 'BUILD_TIME', "\"${buildTime}\""
|
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_M2', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_N);add(chassis.Chassis.GearPosition.GEAR_P);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
||||||
|
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_SWEEPER', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_N);}}'
|
||||||
|
it.buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_VAN', 'null'
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
@@ -64,12 +108,7 @@ android {
|
|||||||
driver {
|
driver {
|
||||||
dimension "multi_device"
|
dimension "multi_device"
|
||||||
buildConfigField 'boolean', 'IS_CLIENT', 'false'
|
buildConfigField 'boolean', 'IS_CLIENT', 'false'
|
||||||
buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_TAXI', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_P);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
|
||||||
buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_BUS', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_N);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
|
||||||
buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_M1', 'null'
|
|
||||||
buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_M2', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_N);add(chassis.Chassis.GearPosition.GEAR_P);add(chassis.Chassis.GearPosition.GEAR_R);}}'
|
|
||||||
buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_SWEEPER', 'new java.util.HashSet<chassis.Chassis.GearPosition>(){{add(chassis.Chassis.GearPosition.GEAR_N);}}'
|
|
||||||
buildConfigField 'java.util.Set<chassis.Chassis.GearPosition>', 'UNABLE_LAUNCH_AUTOPILOT_GEAR_VAN', 'null'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -103,3 +142,103 @@ dependencies {
|
|||||||
// implementation 'com.mogo.cloud:telematic:1.3.59'//注释掉司机端 乘客端
|
// implementation 'com.mogo.cloud:telematic:1.3.59'//注释掉司机端 乘客端
|
||||||
implementation 'com.jcraft:jsch:0.1.55'
|
implementation 'com.jcraft:jsch:0.1.55'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除老的APK
|
||||||
|
def checkRelease() {
|
||||||
|
def runTasks = gradle.startParameter.taskNames
|
||||||
|
for (String task : runTasks) {
|
||||||
|
// 我这里认为执行“assembleRelease”和非“debug”的任务就是执行“release”的任务
|
||||||
|
if (task.contains("assembleRelease") || task.contains("Release")) {
|
||||||
|
deleteOldAPK("release")
|
||||||
|
return true
|
||||||
|
} else if (task.contains("Debug")) {
|
||||||
|
deleteOldAPK("debug")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
//在Moudle 根目录中创建gradle.properties文件存储VersionCode
|
||||||
|
def createFile() {
|
||||||
|
def propFile = file('./gradle.properties')
|
||||||
|
Properties props = new Properties()
|
||||||
|
if (!propFile.exists()) {
|
||||||
|
propFile.createNewFile()
|
||||||
|
props.load(new FileInputStream(propFile))
|
||||||
|
props['VERSION_CODE'] = '1'
|
||||||
|
props.store(propFile.newWriter(), null)
|
||||||
|
} else {
|
||||||
|
props.load(new FileInputStream(propFile))
|
||||||
|
def code = props['VERSION_CODE']
|
||||||
|
if (code == null || code == "0") {
|
||||||
|
props['VERSION_CODE'] = '1'
|
||||||
|
props.store(propFile.newWriter(), null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//读取VersionCode
|
||||||
|
def readVersionCode() {
|
||||||
|
def propFile = file('./gradle.properties')
|
||||||
|
Properties props = new Properties()
|
||||||
|
props.load(new FileInputStream(propFile))
|
||||||
|
// 读取gradle.properties文件中定义的VERSION_CODE属性
|
||||||
|
def code = props['VERSION_CODE'].toInteger()
|
||||||
|
//def code = props.getProperty('VERSION_CODE').toInteger()
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
//当打包的是Release版本时自动更新VersionCode
|
||||||
|
def increasedVersionCode() {
|
||||||
|
def code = readVersionCode()
|
||||||
|
//println("isRelease====" + isRelease)
|
||||||
|
if (isRelease) {
|
||||||
|
code++
|
||||||
|
def propFile = file('./gradle.properties')
|
||||||
|
Properties props = new Properties()
|
||||||
|
props.load(new FileInputStream(propFile))
|
||||||
|
props['VERSION_CODE'] = code.toString()
|
||||||
|
// 将最新的versionCode写入gradle.properties文件中
|
||||||
|
props.store(propFile.newWriter(), null)
|
||||||
|
}
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除无用apk
|
||||||
|
def deleteOldAPK(String buildTypeName) {
|
||||||
|
|
||||||
|
// 使用map创建一个树
|
||||||
|
def tree = fileTree(dir: './build/outputs/apk', include: "${buildTypeName}/*.apk")
|
||||||
|
//println("文件个数:" + tree.size())
|
||||||
|
// 遍历文件树
|
||||||
|
tree.each { File file ->
|
||||||
|
//println("删除文件名称:" + file)
|
||||||
|
file.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def increasedVersionName() {
|
||||||
|
def versionName = "${MAJOR_VERSION}.${MINOR_VERSION}.${readVersionCode()}"
|
||||||
|
return versionName
|
||||||
|
}
|
||||||
|
|
||||||
|
def getBuildTime() {
|
||||||
|
//设置时间格式
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd.HHmmss", Locale.getDefault())
|
||||||
|
//获取当前时间
|
||||||
|
Date curDate = new Date(System.currentTimeMillis())
|
||||||
|
return formatter.format(curDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 获取当前分支名称
|
||||||
|
*/
|
||||||
|
def getWorkingBranchName() {
|
||||||
|
def workingBranchName = ""
|
||||||
|
def proc = "git rev-parse --abbrev-ref HEAD".execute()
|
||||||
|
proc.in.eachLine { line -> workingBranchName = line }
|
||||||
|
proc.err.eachLine { line -> println line }
|
||||||
|
proc.waitFor()
|
||||||
|
workingBranchName = "${workingBranchName}"
|
||||||
|
println "Working branch name: " + workingBranchName
|
||||||
|
return workingBranchName
|
||||||
|
}
|
||||||
2
app_ipc_monitoring/gradle.properties
Normal file
2
app_ipc_monitoring/gradle.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#Wed Mar 01 12:23:40 CST 2023
|
||||||
|
VERSION_CODE=1
|
||||||
@@ -260,7 +260,10 @@ public class VersionFragment extends BaseFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list.add(new Config("ADAS LIB版本:", AdasManager.getInstance().getAdasVersion()));
|
list.add(new Config("ADAS LIB版本:", AdasManager.getInstance().getAdasVersion()));
|
||||||
|
list.add(new Config("APP版本:", BuildConfig.VERSION_NAME));
|
||||||
list.add(new Config("APP构建时间:", BuildConfig.BUILD_TIME));
|
list.add(new Config("APP构建时间:", BuildConfig.BUILD_TIME));
|
||||||
|
list.add(new Config("GIT分支:", BuildConfig.GIT_BRANCH_NAME));
|
||||||
|
list.add(new Config("APK名称:", BuildConfig.APK_NAME));
|
||||||
adapter.setData(list);
|
adapter.setData(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user