harmony 鸿蒙Converting HAR to HSP
Converting HAR to HSP
Currently, the HAR has a problem with duplicate packaging, leading an oversize application package. To fix this problem, you can convert the HAR to the HSP through by the configuration items.
How to Convert
Change the value of type to shared and add the deliveryWithInstall and pages field in the module.json5 file of the HAR module.
// MyApplication\library\src\main\module.json5 { "module": { "type": "shared", "deliveryWithInstall": true, "pages": "$profile:main_pages" // ... } }
Add a string field shared_desc in element of the base, en_US, and zh_CN qualifiers directories under the resources directory.
// MyApplication\library\src\main\resources\base\element\string.json { "string": [ { "name": "shared_desc", "value": "description" } ] }
Add a profile folder in resources > base. Then add a main_pages.json file to the added folder and configure it as follows:
// MyApplication\library\src\main\resources\base\profile\main_pages.json { "src": [ "pages/PageIndex" ] }
Add a pages directory in the ets directory. Then add a PageIndex.ets file in the added directory and configure it as follows:
// MyApplication\library\src\main\ets\pages\PageIndex.ets @Entry @Component struct PageIndex { @State message: string = 'hello world'; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) } .width('100%') } .height('100%') } }
Delete the consumerFiles field from the build-profile.json5 file of the HAR module.
Replace the content in the hvigorfile.ts file of the HAR module with the following content:
// MyApplication\library\hvigorfile.ts import { hspTasks } from '@ohos/hvigor-ohos-plugin'; export default { system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ }
Add the packageType field in the oh-package.json5 file.
// MyApplication\library\oh-package.json5 { "packageType": "InterfaceHar" }
Add the targets tag to build-profile.json5 > modules > library in the root directory of the project.
”`json // MyApplication\build-profile.json5 “modules”: [ { “name”: “library”, “srcPath”: “./library”, “targets”: [ { “name”: “default”, “applyToProducts”: [ “default” ] } ] } ]
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Creating an Application Clone
harmony 鸿蒙app.json5 Configuration File
harmony 鸿蒙Structure of the app Tag
harmony 鸿蒙Overview of Application Configuration Files in FA Model
harmony 鸿蒙Overview of Application Configuration Files in Stage Model
harmony 鸿蒙Application Installation, Uninstall, and Update
harmony 鸿蒙Application Package Overview
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦