zhangbo1_wd

编译新增build_version字段。

... ... @@ -50,6 +50,13 @@
"compileSdkVersion": "5.0.0(12)",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS",
"buildOption": {
"arkOptions": {
"buildProfileFields": {
"BUILD_VERSION": ""
}
}
},
},
{
"name": "productRELEASE",
... ... @@ -57,6 +64,13 @@
"compileSdkVersion": "5.0.0(12)",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS",
"buildOption": {
"arkOptions": {
"buildProfileFields": {
"BUILD_VERSION": ""
}
}
}
}
],
"buildModeSet": [
... ...
... ... @@ -2,7 +2,9 @@
"apiType": "stageMode",
"buildOption": {
"arkOptions": {
// "apPath": "./modules.ap" /* Profile used for profile-guided optimization (PGO), a compiler optimization technique to improve app runtime performance. */
"buildProfileFields": {
"BUILD_TIME": ""
}
}
},
"buildOptionSet": [
... ... @@ -16,6 +18,9 @@
"./obfuscation-rules.txt"
]
}
},
"buildProfileFields": {
"BUILD_TIME": ""
}
}
},
... ...
import { hspTasks } from '@ohos/hvigor-ohos-plugin';
import { appTasks, OhosAppContext, OhosPluginId } from '@ohos/hvigor-ohos-plugin';
import { hvigor, getNode } from '@ohos/hvigor'
// 获取根节点
const rootNode = getNode(__filename);
// 为根节点添加一个afterNodeEvaluate hook 在hook中修改根目录下的build-profile.json5的内容并使能
rootNode.afterNodeEvaluate(node => {
// 获取app插件的上下文对象
const appContext = node.getContext(OhosPluginId.OHOS_HSP_PLUGIN) as OhosHspContext;
// 通过上下文对象获取从根目录build-profile.json5文件中读出来的obj对象
const buildProfileOpt = appContext.getBuildProfileOpt();
buildProfileOpt['buildOption']['arkOptions']['buildProfileFields'] = {
"BUILD_VERSION": getBuildVersion(),
};
// 将obj对象设置回上下文对象以使能到构建的过程与结果中
appContext.setBuildProfileOpt(buildProfileOpt);
})
export default {
system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
plugins: [] /* Custom plugin to extend the functionality of Hvigor. */
}
function getBuildVersion() {
// build时间作为版本
let now = new Date()
let year = now.getFullYear()
let month = ('0' + (now.getMonth() + 1)).slice(-2)
let day = ('0' + (now.getDate())).slice(-2)
let hours = ('0' + (now.getHours())).slice(-2)
let minutes = ('0' + (now.getMinutes())).slice(-2)
let str = year + month + day + hours + minutes
return str;
}
\ No newline at end of file
... ...
import bundleManager from '@ohos.bundle.bundleManager';
import common from '@ohos.app.ability.common';
import { Logger } from './Logger';
import BuildProfile from 'BuildProfile';
const TAG: string = 'AppUtils';
... ... @@ -8,9 +9,14 @@ const TAG: string = 'AppUtils';
* 与应用相关属性或操作
*/
export class AppUtils {
private static buildVersion: string = ''
static {
AppUtils.buildVersion = BuildProfile.BUILD_VERSION;
}
/**
* 获取应用名称
* 即:咪咕视频
* 即:人民日报
*/
static getAppName(context: common.Context): string {
// todo:获取到的是 $string:app_name
... ... @@ -20,7 +26,6 @@ export class AppUtils {
/**
* 获取应用的包名
* 即:com.cmcc.myapplication
*/
static getPackageName(context: common.Context): string {
return context.applicationInfo?.name;
... ... @@ -74,5 +79,12 @@ export class AppUtils {
}
return '';
}
/**
* 应用build版本,时间,如:'202405291450'
*/
static getBuildVersion(): string {
return AppUtils.buildVersion;
}
}
... ...
... ... @@ -16,7 +16,7 @@ export class HttpParams {
headers['plat'] = DeviceUtil.getPlat()
headers['Content-Type'] = 'application/json; charset=utf-8'
headers['device_id'] = DeviceUtil.clientId()
headers['build_version'] = HttpParams.getVersion()
headers['build_version'] = AppUtils.getBuildVersion()
headers['adcode'] = HttpUtils.getProvinceCode()
headers['os_version'] = DeviceUtil.getOsVersion()
headers['system'] = AppUtils.getOSName()
... ... @@ -80,9 +80,4 @@ export class HttpParams {
headers['city_dode'] = encodeURI(cityCode)
}
}
private static getVersion() {
// TODO build时间,待对接build生成属性
return '202401242103';
}
}
\ No newline at end of file
... ...
... ... @@ -47,7 +47,7 @@ export struct AboutPageUI {
context.getApplicationContext();
let appVerion = AppUtils.getAppVersionName()
if (StringUtils.isNotEmpty(appVerion)) {
this.version = "版本号:" + appVerion
this.version = "版本号:" + appVerion + '.' + AppUtils.getBuildVersion()
}
}
... ...