From 2cb2fe56e0cff3c31b0e7ad29500f62adea3e523 Mon Sep 17 00:00:00 2001 From: wangxinbo Date: Fri, 16 May 2025 15:27:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20CompilingAndBuilding=20FAQ=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ErrorOccurredWhileBuildingHSPModule.ets | 71 ------------------- .../resources/base/profile/main_pages.json | 4 +- CompilingAndBuilding/hvigorfile.ts | 10 ++- CompilingAndBuilding/hvigorfile_hsp.ts | 56 +++++++++++++++ ...ushPackageDebuggingError.ets => plugin.ts} | 42 +++-------- 5 files changed, 77 insertions(+), 106 deletions(-) delete mode 100644 CompilingAndBuilding/entry/src/main/ets/pages/ErrorOccurredWhileBuildingHSPModule.ets create mode 100644 CompilingAndBuilding/hvigorfile_hsp.ts rename CompilingAndBuilding/{entry/src/main/ets/pages/PushPackageDebuggingError.ets => plugin.ts} (80%) diff --git a/CompilingAndBuilding/entry/src/main/ets/pages/ErrorOccurredWhileBuildingHSPModule.ets b/CompilingAndBuilding/entry/src/main/ets/pages/ErrorOccurredWhileBuildingHSPModule.ets deleted file mode 100644 index d044ff7..0000000 --- a/CompilingAndBuilding/entry/src/main/ets/pages/ErrorOccurredWhileBuildingHSPModule.ets +++ /dev/null @@ -1,71 +0,0 @@ -/* -* Copyright (c) 2024 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* -* FAQ:构建HSP模块时报错“Ohos BundleTool [Error]: hsp has home ability;Ohos BundleTool [Error]: CompressEntrance::main exit, verify failed.” - */ - -// DocsCode 1 -// HSP模块hvigorfile.ts -import { hspTasks,OhosPluginId, Target } from '@ohos/hvigor-ohos-plugin'; -import { hvigor, HvigorNode, HvigorPlugin,FileUtil } from '@ohos/hvigor'; -export function customPlugin():HvigorPlugin { - return { - pluginId: 'customPlugin', - context() { - return { - data: 'customPlugin xxx' - }; - }, - apply(currentNode:HvigorNode): Promise { - hvigor.nodesEvaluated(async () => { - hspTask(currentNode); - }); - } - } -} -function hspTask(currentNode: HvigorNode) { - // 获取hsp模块上下文信息 - const hspContext = currentNode.getContext(OhosPluginId.OHOS_HSP_PLUGIN) as OhosHspContext; - hspContext?.targets((target: Target) => { - const targetName = target.getTargetName(); - const outputPath = target.getBuildTargetOutputPath(); - const task = currentNode.getTaskByName(`${targetName}@GeneratePkgModuleJson`); - currentNode.registerTask({ - // 任务名称 - name: `${targetName}@changeModuleJson`, - // 任务执行逻辑主体函数 - run() { - const moduleJson = FileUtil.readJson5(outputPath+"/../../intermediates/package/"+targetName+"/module.json"); - const abilities = moduleJson['module']['abilities']; - abilities.forEach((ability)=>{ - delete ability['skills']; - }) - console.log('begin to rewrite module.json file.'); - moduleJson['module']['abilities'] = abilities - FileUtil.writeFileSync(outputPath+"/../../intermediates/package/"+targetName+"/module.json",JSON.stringify(moduleJson)); - }, - // 配置前置任务依赖 - dependencies: [`${targetName}@GeneratePkgModuleJson`], - // 配置任务的后置任务依赖 - postDependencies: [`${targetName}@PackageSharedHar`] - }); - }); -} -export default { - system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ - plugins:[customPlugin()] /* Custom plugin to extend the functionality of Hvigor. */ -} -// DocsCode 1 \ No newline at end of file diff --git a/CompilingAndBuilding/entry/src/main/resources/base/profile/main_pages.json b/CompilingAndBuilding/entry/src/main/resources/base/profile/main_pages.json index 2e45e7c..55c3f00 100644 --- a/CompilingAndBuilding/entry/src/main/resources/base/profile/main_pages.json +++ b/CompilingAndBuilding/entry/src/main/resources/base/profile/main_pages.json @@ -1,7 +1,5 @@ { "src": [ - "pages/Index", - "pages/PushPackageDebuggingError", - "pages/ErrorOccurredWhileBuildingHSPModule" + "pages/Index" ] } \ No newline at end of file diff --git a/CompilingAndBuilding/hvigorfile.ts b/CompilingAndBuilding/hvigorfile.ts index f3cb9f1..4fd792b 100644 --- a/CompilingAndBuilding/hvigorfile.ts +++ b/CompilingAndBuilding/hvigorfile.ts @@ -1,6 +1,14 @@ +/* +* FAQ:推包调试报错“Error message:cannot find record '&XXX/src/main/ets/YYY&x.y.z', please check the request path.'ZZZ.abc'.” + */ + +// [Start hvigor_config] import { appTasks } from '@ohos/hvigor-ohos-plugin'; +import { updateAbcVersionPlugin, updateHarAbcVersionPlugin } from './plugin.ts'; + export default { system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ - plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ + plugins:[updateAbcVersionPlugin(), updateHarAbcVersionPlugin()] /* Custom plugin to extend the functionality of Hvigor. */ } +// [End hvigor_config] \ No newline at end of file diff --git a/CompilingAndBuilding/hvigorfile_hsp.ts b/CompilingAndBuilding/hvigorfile_hsp.ts new file mode 100644 index 0000000..706e7a7 --- /dev/null +++ b/CompilingAndBuilding/hvigorfile_hsp.ts @@ -0,0 +1,56 @@ +/* +* FAQ:构建HSP模块时报错“Ohos BundleTool [Error]: hsp has home ability;Ohos BundleTool [Error]: CompressEntrance::main exit, verify failed.” + */ + +// [Start custom_plugin] +// HSP模块hvigorfile.ts +import { hspTasks,OhosPluginId, Target } from '@ohos/hvigor-ohos-plugin'; +import { hvigor, HvigorNode, HvigorPlugin,FileUtil } from '@ohos/hvigor'; +export function customPlugin():HvigorPlugin { + return { + pluginId: 'customPlugin', + context() { + return { + data: 'customPlugin xxx' + }; + }, + apply(currentNode:HvigorNode): Promise { + hvigor.nodesEvaluated(async () => { + hspTask(currentNode); + }); + } + } +} +function hspTask(currentNode: HvigorNode) { + // 获取hsp模块上下文信息 + const hspContext = currentNode.getContext(OhosPluginId.OHOS_HSP_PLUGIN) as OhosHspContext; + hspContext?.targets((target: Target) => { + const targetName = target.getTargetName(); + const outputPath = target.getBuildTargetOutputPath(); + const task = currentNode.getTaskByName(`${targetName}@GeneratePkgModuleJson`); + currentNode.registerTask({ + // 任务名称 + name: `${targetName}@changeModuleJson`, + // 任务执行逻辑主体函数 + run() { + const moduleJson = FileUtil.readJson5(outputPath+"/../../intermediates/package/"+targetName+"/module.json"); + const abilities = moduleJson['module']['abilities']; + abilities.forEach((ability)=>{ + delete ability['skills']; + }) + console.log('begin to rewrite module.json file.'); + moduleJson['module']['abilities'] = abilities + FileUtil.writeFileSync(outputPath+"/../../intermediates/package/"+targetName+"/module.json",JSON.stringify(moduleJson)); + }, + // 配置前置任务依赖 + dependencies: [`${targetName}@GeneratePkgModuleJson`], + // 配置任务的后置任务依赖 + postDependencies: [`${targetName}@PackageSharedHar`] + }); + }); +} +export default { + system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[customPlugin()] /* Custom plugin to extend the functionality of Hvigor. */ +} +// [End custom_plugin] \ No newline at end of file diff --git a/CompilingAndBuilding/entry/src/main/ets/pages/PushPackageDebuggingError.ets b/CompilingAndBuilding/plugin.ts similarity index 80% rename from CompilingAndBuilding/entry/src/main/ets/pages/PushPackageDebuggingError.ets rename to CompilingAndBuilding/plugin.ts index 377fff6..aab5e3f 100644 --- a/CompilingAndBuilding/entry/src/main/ets/pages/PushPackageDebuggingError.ets +++ b/CompilingAndBuilding/plugin.ts @@ -1,36 +1,24 @@ -/* -* Copyright (c) 2024 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - /* * FAQ:推包调试报错“Error message:cannot find record '&XXX/src/main/ets/YYY&x.y.z', please check the request path.'ZZZ.abc'.” */ -// DocsCode 1 +// [Start update_har_abc_version_plugin] import {OhosPluginId, Target} from '@ohos/hvigor-ohos-plugin'; import {hvigor, HvigorNode, HvigorPlugin} from '@ohos/hvigor'; import path from "path"; import fs from "fs"; + function getLoaderJsonPath(target: Target) { return path.resolve(target.getBuildTargetOutputPath(), `../../intermediates/loader/${target.getTargetName()}/loader.json`); } + function getPkgContextInfoPath(target: Target) { return path.resolve(target.getBuildTargetOutputPath(), `../../intermediates/loader/${target.getTargetName()}/pkgContextInfo.json`); } + function deleteLoaderJson(target: Target) { const loaderJsonPath = getLoaderJsonPath(target); if (fs.existsSync(loaderJsonPath)) { @@ -38,6 +26,7 @@ function deleteLoaderJson(target: Target) { } } + function deletePkgContextInfo(target: Target) { const pkgContextInfoPath = getPkgContextInfoPath(target); if (fs.existsSync(pkgContextInfoPath)) { @@ -45,6 +34,7 @@ function deletePkgContextInfo(target: Target) { } } + function deleteRollupCache(target: Target, buildMode: string) { const arkTSCompileCachePath = path.resolve(target.getBuildTargetOutputPath(), `../../cache/${target.getTargetName()}/${target.getTargetName()}@HarCompileArkTS/esmodule/${buildMode}/compiler.cache`); @@ -53,6 +43,7 @@ function deleteRollupCache(target: Target, buildMode: string) { } } + function updateHapHspAbcVersion(subNode: HvigorNode, target: Target) { const task = subNode.getTaskByName(`${target.getTargetName()}@GenerateLoaderJson`); if (!task) { @@ -95,12 +86,14 @@ function updateHapHspAbcVersion(subNode: HvigorNode, target: Target) { }); } + function updateHarAbcVersion(target: Target) { deleteLoaderJson(target); deleteRollupCache(target, 'debug'); deleteRollupCache(target, 'release'); } + // 字节码har的使用方使用此插件,在集成字节码har时,可以正确修改abc中ohmurl的版本号,保证运行时不闪退 export function updateAbcVersionPlugin(): HvigorPlugin { return { @@ -124,6 +117,7 @@ export function updateAbcVersionPlugin(): HvigorPlugin { }; } + // 字节码har的生成方使用此插件,在修改版本号之后可以增量构建出ohmurl正确的字节码har export function updateHarAbcVersionPlugin(): HvigorPlugin { return { @@ -143,18 +137,4 @@ export function updateHarAbcVersionPlugin(): HvigorPlugin { } }; } -// DocsCode 1 - -// DocsCode 2 -import { appTasks } from '@ohos/hvigor-ohos-plugin'; -import { updateAbcVersionPlugin, updateHarAbcVersionPlugin } from './plugin.ts'; - -export default { - system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ - plugins:[updateAbcVersionPlugin(), updateHarAbcVersionPlugin()] /* Custom plugin to extend the functionality of Hvigor. */ -} -// DocsCode 2 - -// DocsCode 3 -hvigorw --stop-daemon -// DocsCode 3 \ No newline at end of file +// [End update_har_abc_version_plugin] \ No newline at end of file -- Gitee From b199c648efe6429497633288c6d32b8ac0902b91 Mon Sep 17 00:00:00 2001 From: kejintao Date: Sat, 17 May 2025 06:48:50 +0000 Subject: [PATCH 2/2] =?UTF-8?q?compiling1=E4=BF=AE=E6=94=B9=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E4=B8=BA=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kejintao --- CompilingAndBuilding/hvigorfile_hsp.ts | 12 ++++++------ CompilingAndBuilding/plugin.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CompilingAndBuilding/hvigorfile_hsp.ts b/CompilingAndBuilding/hvigorfile_hsp.ts index 706e7a7..a6f6aa3 100644 --- a/CompilingAndBuilding/hvigorfile_hsp.ts +++ b/CompilingAndBuilding/hvigorfile_hsp.ts @@ -3,7 +3,7 @@ */ // [Start custom_plugin] -// HSP模块hvigorfile.ts +// HSP module hvigorfile.ts import { hspTasks,OhosPluginId, Target } from '@ohos/hvigor-ohos-plugin'; import { hvigor, HvigorNode, HvigorPlugin,FileUtil } from '@ohos/hvigor'; export function customPlugin():HvigorPlugin { @@ -22,16 +22,16 @@ export function customPlugin():HvigorPlugin { } } function hspTask(currentNode: HvigorNode) { - // 获取hsp模块上下文信息 + // Obtain contextual information of the HSP module const hspContext = currentNode.getContext(OhosPluginId.OHOS_HSP_PLUGIN) as OhosHspContext; hspContext?.targets((target: Target) => { const targetName = target.getTargetName(); const outputPath = target.getBuildTargetOutputPath(); const task = currentNode.getTaskByName(`${targetName}@GeneratePkgModuleJson`); currentNode.registerTask({ - // 任务名称 + // TASK name: `${targetName}@changeModuleJson`, - // 任务执行逻辑主体函数 + // Task execution logic entity function run() { const moduleJson = FileUtil.readJson5(outputPath+"/../../intermediates/package/"+targetName+"/module.json"); const abilities = moduleJson['module']['abilities']; @@ -42,9 +42,9 @@ function hspTask(currentNode: HvigorNode) { moduleJson['module']['abilities'] = abilities FileUtil.writeFileSync(outputPath+"/../../intermediates/package/"+targetName+"/module.json",JSON.stringify(moduleJson)); }, - // 配置前置任务依赖 + // Configure prerequisite task dependencies dependencies: [`${targetName}@GeneratePkgModuleJson`], - // 配置任务的后置任务依赖 + // Post task dependencies for configuring tasks postDependencies: [`${targetName}@PackageSharedHar`] }); }); diff --git a/CompilingAndBuilding/plugin.ts b/CompilingAndBuilding/plugin.ts index aab5e3f..9af6dfa 100644 --- a/CompilingAndBuilding/plugin.ts +++ b/CompilingAndBuilding/plugin.ts @@ -94,7 +94,7 @@ function updateHarAbcVersion(target: Target) { } -// 字节码har的使用方使用此插件,在集成字节码har时,可以正确修改abc中ohmurl的版本号,保证运行时不闪退 +// The user of bytecode har can use this plugin to correctly modify the version number of ohmurl in abc when integrating bytecode har, ensuring no crashes during runtime export function updateAbcVersionPlugin(): HvigorPlugin { return { pluginId: 'updateAbcVersionPlugin', @@ -118,7 +118,7 @@ export function updateAbcVersionPlugin(): HvigorPlugin { } -// 字节码har的生成方使用此插件,在修改版本号之后可以增量构建出ohmurl正确的字节码har +// The generator of bytecode har uses this plugin to incrementally build ohmurl with the correct bytecode har after modifying the version number export function updateHarAbcVersionPlugin(): HvigorPlugin { return { pluginId: 'updateHarAbcVersionPlugin', -- Gitee