HarmonyOS学习,灵活运用工程结构及应用程序结构

HarmonyOS学习,灵活运用工程结构及应用程序结构

工程结构及应用程序结构
一、自定义工程框架
在这里插入图片描述

1、在工程目录下的build-profile.json5文件中定义app参数和多模块数组参数(并设置phone模块为主模块)。一个模块配置一个子目录。
应用的主模块。一个APP中,对于同一设备类型必须有且只有一个入口Entry类型的模块。
{
“app”: {
“signingConfigs”: [],
“compileSdkVersion”: 9,
“compatibleSdkVersion”: 9,
“products”: [
{
“name”: “default”,
“signingConfig”: “default”,
}
]
},
“modules”: [
{
“name”: “phone”,
“srcPath”: “./product/phone”,
“targets”: [
{
“name”: “default”,
“applyToProducts”: [
“default”
]
}
]
},
{
“name”: “common”,
“srcPath”: “./common”
},
{
“name”: “home”,
“srcPath”: “./features/home”
},
{
“name”: “newproduct”,
“srcPath”: “./features/newproduct”
},
{
“name”: “shopcart”,
“srcPath”: “./features/shopcart”
},
{
“name”: “personal”,
“srcPath”: “./features/personal”
},
{
“name”: “commoditydetail”,
“srcPath”: “./features/commoditydetail”
},
{
“name”: “orderdetail”,
“srcPath”: “./features/orderdetail”
}
]
}

2、在主模块目录下oh-package.json5文件中配置dependencies,将模块关联关键字
{
“license”: “ISC”,
“devDependencies”: {},
“name”: “phone”,
“description”: “example description”,
“repository”: {},
“version”: “1.0.0”,
“dependencies”: {
“@ohos/orderdetail”: “file:…/…/features/orderdetail”,
“@ohos/commoditydetail”: “…/…/features/commoditydetail”,
“@ohos/newproduct”: “…/…/features/newproduct”,
“@ohos/home”: “…/…/features/home”,
“@ohos/common”: “file:…/…/common”,
“@ohos/personal”: “…/…/features/personal”,
“@ohos/shopcart”: “…/…/features/shopcart”
}
}

3、在主模块的子目录src/main下的文件module.json5配置EntryAbility的相关参数

{
“module”: {
“name”: “phone”,
“type”: “entry”,
“description”: “ s t r i n g : m o d u l e d e s c " , " m a i n E l e m e n t " : " E n t r y A b i l i t y " , " d e v i c e T y p e s " : [ " p h o n e " , " t a b l e t " ] , " d e l i v e r y W i t h I n s t a l l " : t r u e , " i n s t a l l a t i o n F r e e " : f a l s e , " p a g e s " : " string:module_desc", "mainElement": "EntryAbility", "deviceTypes": [ "phone", "tablet" ], "deliveryWithInstall": true, "installationFree": false, "pages": " string:moduledesc","mainElement":"EntryAbility","deviceTypes":["phone","tablet"],"deliveryWithInstall":true,"installationFree":false,"pages":"profile:main_pages”,
“abilities”: [
{
“name”: “EntryAbility”,
“srcEntry”: “./ets/entryability/EntryAbility.ets”,
“description”: “ s t r i n g : E n t r y A b i l i t y d e s c " , " i c o n " : " string:EntryAbility_desc", "icon": " string:EntryAbilitydesc","icon":"media:icon”,
“label”: “ s t r i n g : E n t r y A b i l i t y l a b e l " , " s t a r t W i n d o w I c o n " : " string:EntryAbility_label", "startWindowIcon": " string:EntryAbilitylabel","startWindowIcon":"media:icon”,
“startWindowBackground”: “$color:start_window_background”,
“exported”: true,
“skills”: [
{
“entities”: [
“entity.system.home”
],
“actions”: [
“action.system.home”
]
}
]
}
]
}
}

在这里插入图片描述
在这里插入图片描述

设置主页"pages": “$profile:main_pages”,main_pages.json设置主页参数,并且各主页参数对应的控件都需要用@Entry装饰器装饰
{
“src”: [
“pages/SplashPage”,
“pages/MainPage”,
“pages/CommodityDetailPage”,
“pages/ConfirmOrderPage”,
“pages/PayOrderPage”,
“pages/OrderDetailListPage”
]
}

4、选择其中一个子模块,例如common子模块,配置oh-package.json5文件设置主页面为index.ets.

Index.ets的内容,是将本模块控件export
在这里插入图片描述
在这里插入图片描述

  • 19
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值