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 d044ff7124031ac8294fb94ed415e62ad448235e..0000000000000000000000000000000000000000 --- 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 2e45e7c7694ac43d507de8d2f851dfe1c15a082a..55c3f007f87b7ce5206d325f968cc56f2f79441f 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 f3cb9f1a87a81687554a76283af8df27d8bda775..4fd792be8432c4cd69969501d871cba25b89d618 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 0000000000000000000000000000000000000000..a6f6aa324c76f60b0fa5396363b6734a2baaee42 --- /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 module 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) { + // 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']; + 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)); + }, + // Configure prerequisite task dependencies + dependencies: [`${targetName}@GeneratePkgModuleJson`], + // Post task dependencies for configuring tasks + 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 75% rename from CompilingAndBuilding/entry/src/main/ets/pages/PushPackageDebuggingError.ets rename to CompilingAndBuilding/plugin.ts index 377fff638e668c6ea11151a485d0411bebc16d23..9af6dfadc2d3870c326af3be30daff1398593734 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,13 +86,15 @@ function updateHapHspAbcVersion(subNode: HvigorNode, target: Target) { }); } + function updateHarAbcVersion(target: Target) { deleteLoaderJson(target); deleteRollupCache(target, 'debug'); deleteRollupCache(target, 'release'); } -// 字节码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', @@ -124,7 +117,8 @@ 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', @@ -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