Showing
6 changed files
with
67 additions
and
12 deletions
| @@ -50,6 +50,13 @@ | @@ -50,6 +50,13 @@ | ||
| 50 | "compileSdkVersion": "5.0.0(12)", | 50 | "compileSdkVersion": "5.0.0(12)", |
| 51 | "compatibleSdkVersion": "5.0.0(12)", | 51 | "compatibleSdkVersion": "5.0.0(12)", |
| 52 | "runtimeOS": "HarmonyOS", | 52 | "runtimeOS": "HarmonyOS", |
| 53 | + "buildOption": { | ||
| 54 | + "arkOptions": { | ||
| 55 | + "buildProfileFields": { | ||
| 56 | + "BUILD_VERSION": "" | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + }, | ||
| 53 | }, | 60 | }, |
| 54 | { | 61 | { |
| 55 | "name": "productRELEASE", | 62 | "name": "productRELEASE", |
| @@ -57,6 +64,13 @@ | @@ -57,6 +64,13 @@ | ||
| 57 | "compileSdkVersion": "5.0.0(12)", | 64 | "compileSdkVersion": "5.0.0(12)", |
| 58 | "compatibleSdkVersion": "5.0.0(12)", | 65 | "compatibleSdkVersion": "5.0.0(12)", |
| 59 | "runtimeOS": "HarmonyOS", | 66 | "runtimeOS": "HarmonyOS", |
| 67 | + "buildOption": { | ||
| 68 | + "arkOptions": { | ||
| 69 | + "buildProfileFields": { | ||
| 70 | + "BUILD_VERSION": "" | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + } | ||
| 60 | } | 74 | } |
| 61 | ], | 75 | ], |
| 62 | "buildModeSet": [ | 76 | "buildModeSet": [ |
| @@ -2,7 +2,9 @@ | @@ -2,7 +2,9 @@ | ||
| 2 | "apiType": "stageMode", | 2 | "apiType": "stageMode", |
| 3 | "buildOption": { | 3 | "buildOption": { |
| 4 | "arkOptions": { | 4 | "arkOptions": { |
| 5 | - // "apPath": "./modules.ap" /* Profile used for profile-guided optimization (PGO), a compiler optimization technique to improve app runtime performance. */ | 5 | + "buildProfileFields": { |
| 6 | + "BUILD_TIME": "" | ||
| 7 | + } | ||
| 6 | } | 8 | } |
| 7 | }, | 9 | }, |
| 8 | "buildOptionSet": [ | 10 | "buildOptionSet": [ |
| @@ -16,6 +18,9 @@ | @@ -16,6 +18,9 @@ | ||
| 16 | "./obfuscation-rules.txt" | 18 | "./obfuscation-rules.txt" |
| 17 | ] | 19 | ] |
| 18 | } | 20 | } |
| 21 | + }, | ||
| 22 | + "buildProfileFields": { | ||
| 23 | + "BUILD_TIME": "" | ||
| 19 | } | 24 | } |
| 20 | } | 25 | } |
| 21 | }, | 26 | }, |
| 1 | import { hspTasks } from '@ohos/hvigor-ohos-plugin'; | 1 | import { hspTasks } from '@ohos/hvigor-ohos-plugin'; |
| 2 | +import { appTasks, OhosAppContext, OhosPluginId } from '@ohos/hvigor-ohos-plugin'; | ||
| 3 | +import { hvigor, getNode } from '@ohos/hvigor' | ||
| 4 | + | ||
| 5 | +// 获取根节点 | ||
| 6 | +const rootNode = getNode(__filename); | ||
| 7 | +// 为根节点添加一个afterNodeEvaluate hook 在hook中修改根目录下的build-profile.json5的内容并使能 | ||
| 8 | +rootNode.afterNodeEvaluate(node => { | ||
| 9 | + // 获取app插件的上下文对象 | ||
| 10 | + const appContext = node.getContext(OhosPluginId.OHOS_HSP_PLUGIN) as OhosHspContext; | ||
| 11 | + // 通过上下文对象获取从根目录build-profile.json5文件中读出来的obj对象 | ||
| 12 | + const buildProfileOpt = appContext.getBuildProfileOpt(); | ||
| 13 | + buildProfileOpt['buildOption']['arkOptions']['buildProfileFields'] = { | ||
| 14 | + "BUILD_VERSION": getBuildVersion(), | ||
| 15 | + }; | ||
| 16 | + // 将obj对象设置回上下文对象以使能到构建的过程与结果中 | ||
| 17 | + appContext.setBuildProfileOpt(buildProfileOpt); | ||
| 18 | +}) | ||
| 2 | 19 | ||
| 3 | export default { | 20 | export default { |
| 4 | - system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ | ||
| 5 | - plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ | 21 | + system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ |
| 22 | + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ | ||
| 6 | } | 23 | } |
| 24 | + | ||
| 25 | +function getBuildVersion() { | ||
| 26 | + // build时间作为版本 | ||
| 27 | + let now = new Date() | ||
| 28 | + let year = now.getFullYear() | ||
| 29 | + let month = ('0' + (now.getMonth() + 1)).slice(-2) | ||
| 30 | + let day = ('0' + (now.getDate())).slice(-2) | ||
| 31 | + let hours = ('0' + (now.getHours())).slice(-2) | ||
| 32 | + let minutes = ('0' + (now.getMinutes())).slice(-2) | ||
| 33 | + let str = year + month + day + hours + minutes | ||
| 34 | + return str; | ||
| 35 | +} |
| 1 | import bundleManager from '@ohos.bundle.bundleManager'; | 1 | import bundleManager from '@ohos.bundle.bundleManager'; |
| 2 | import common from '@ohos.app.ability.common'; | 2 | import common from '@ohos.app.ability.common'; |
| 3 | import { Logger } from './Logger'; | 3 | import { Logger } from './Logger'; |
| 4 | +import BuildProfile from 'BuildProfile'; | ||
| 4 | 5 | ||
| 5 | const TAG: string = 'AppUtils'; | 6 | const TAG: string = 'AppUtils'; |
| 6 | 7 | ||
| @@ -8,9 +9,14 @@ const TAG: string = 'AppUtils'; | @@ -8,9 +9,14 @@ const TAG: string = 'AppUtils'; | ||
| 8 | * 与应用相关属性或操作 | 9 | * 与应用相关属性或操作 |
| 9 | */ | 10 | */ |
| 10 | export class AppUtils { | 11 | export class AppUtils { |
| 12 | + private static buildVersion: string = '' | ||
| 13 | + static { | ||
| 14 | + AppUtils.buildVersion = BuildProfile.BUILD_VERSION; | ||
| 15 | + } | ||
| 16 | + | ||
| 11 | /** | 17 | /** |
| 12 | * 获取应用名称 | 18 | * 获取应用名称 |
| 13 | - * 即:咪咕视频 | 19 | + * 即:人民日报 |
| 14 | */ | 20 | */ |
| 15 | static getAppName(context: common.Context): string { | 21 | static getAppName(context: common.Context): string { |
| 16 | // todo:获取到的是 $string:app_name | 22 | // todo:获取到的是 $string:app_name |
| @@ -20,7 +26,6 @@ export class AppUtils { | @@ -20,7 +26,6 @@ export class AppUtils { | ||
| 20 | 26 | ||
| 21 | /** | 27 | /** |
| 22 | * 获取应用的包名 | 28 | * 获取应用的包名 |
| 23 | - * 即:com.cmcc.myapplication | ||
| 24 | */ | 29 | */ |
| 25 | static getPackageName(context: common.Context): string { | 30 | static getPackageName(context: common.Context): string { |
| 26 | return context.applicationInfo?.name; | 31 | return context.applicationInfo?.name; |
| @@ -74,5 +79,12 @@ export class AppUtils { | @@ -74,5 +79,12 @@ export class AppUtils { | ||
| 74 | } | 79 | } |
| 75 | return ''; | 80 | return ''; |
| 76 | } | 81 | } |
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 应用build版本,时间,如:'202405291450' | ||
| 85 | + */ | ||
| 86 | + static getBuildVersion(): string { | ||
| 87 | + return AppUtils.buildVersion; | ||
| 88 | + } | ||
| 77 | } | 89 | } |
| 78 | 90 |
| @@ -16,7 +16,7 @@ export class HttpParams { | @@ -16,7 +16,7 @@ export class HttpParams { | ||
| 16 | headers['plat'] = DeviceUtil.getPlat() | 16 | headers['plat'] = DeviceUtil.getPlat() |
| 17 | headers['Content-Type'] = 'application/json; charset=utf-8' | 17 | headers['Content-Type'] = 'application/json; charset=utf-8' |
| 18 | headers['device_id'] = DeviceUtil.clientId() | 18 | headers['device_id'] = DeviceUtil.clientId() |
| 19 | - headers['build_version'] = HttpParams.getVersion() | 19 | + headers['build_version'] = AppUtils.getBuildVersion() |
| 20 | headers['adcode'] = HttpUtils.getProvinceCode() | 20 | headers['adcode'] = HttpUtils.getProvinceCode() |
| 21 | headers['os_version'] = DeviceUtil.getOsVersion() | 21 | headers['os_version'] = DeviceUtil.getOsVersion() |
| 22 | headers['system'] = AppUtils.getOSName() | 22 | headers['system'] = AppUtils.getOSName() |
| @@ -80,9 +80,4 @@ export class HttpParams { | @@ -80,9 +80,4 @@ export class HttpParams { | ||
| 80 | headers['city_dode'] = encodeURI(cityCode) | 80 | headers['city_dode'] = encodeURI(cityCode) |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | - | ||
| 84 | - private static getVersion() { | ||
| 85 | - // TODO build时间,待对接build生成属性 | ||
| 86 | - return '202401242103'; | ||
| 87 | - } | ||
| 88 | } | 83 | } |
| @@ -47,7 +47,7 @@ export struct AboutPageUI { | @@ -47,7 +47,7 @@ export struct AboutPageUI { | ||
| 47 | context.getApplicationContext(); | 47 | context.getApplicationContext(); |
| 48 | let appVerion = AppUtils.getAppVersionName() | 48 | let appVerion = AppUtils.getAppVersionName() |
| 49 | if (StringUtils.isNotEmpty(appVerion)) { | 49 | if (StringUtils.isNotEmpty(appVerion)) { |
| 50 | - this.version = "版本号:" + appVerion | 50 | + this.version = "版本号:" + appVerion + '.' + AppUtils.getBuildVersion() |
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| 53 | 53 |
-
Please register or login to post a comment