一、ArkUI框架

ArkUI框架是鸿蒙开发中使用的一套UI框架,类似于Android或iOS中的UI一样,具备了界面布局、动画、UI交互等基本功能。方舟开发框架采用了基于ArkTS语言声明式开发范式。UI的更新方式采用数据驱动

二、应用模型

应用模型,就是应用程序运行所必须具备的能力和运行机制。

Stage模型是 HarmonyOS API 9开始新增的应用模型,是官方主推并且会长期支持的应用模型。

三、项目的目录结构

目录结构.png

1.app.json5配置文件

  1. {
  2. "app": {
  3. "bundleName": "com.example.myapplication",
  4. "vendor": "example",
  5. "versionCode": 1000000,
  6. "versionName": "1.0.0",
  7. "icon": "$media:app_icon",
  8. "label": "$string:app_name"
  9. }
  10. }

2.module.json5配置文件

  1. {
  2. "module": {
  3. "name": "entry",
  4. "type": "entry",
  5. "description": "$string:module_desc",
  6. "mainElement": "EntryAbility",
  7. "deviceTypes": [
  8. "phone"
  9. ],
  10. "deliveryWithInstall": true,
  11. "installationFree": false,
  12. "pages": "$profile:main_pages",
  13. "abilities": [
  14. {
  15. "name": "EntryAbility",
  16. "srcEntry": "./ets/entryability/EntryAbility.ets",
  17. "description": "$string:ability_desc",
  18. "icon": "$media:icon",
  19. "label": "$string:ability_label",
  20. "startWindowIcon": "$media:startIcon",
  21. "startWindowBackground": "$color:start_window_background",
  22. "exported": true,
  23. "skills": [
  24. {
  25. "entities": [
  26. "entity.system.home"
  27. ],
  28. "actions": [
  29. "action.system.home"
  30. ]
  31. }
  32. ]
  33. }
  34. ]
  35. }
  36. }

3.模块级build-profile.json5配置文件

  1. {
  2. "apiType": "stageMode",
  3. "buildOption": {
  4. },
  5. "buildOptionSet": [
  6. {
  7. "name": "release",
  8. "arkOptions": {
  9. "obfuscation": {
  10. "ruleOptions": {
  11. "enable": true,
  12. "files": [
  13. "./obfuscation-rules.txt"
  14. ]
  15. }
  16. }
  17. }
  18. },
  19. ],
  20. "targets": [
  21. {
  22. "name": "default"
  23. },
  24. {
  25. "name": "ohosTest",
  26. }
  27. ]
  28. }

4.模块级构建脚本hvigorfile.ts文件

  1. import { hapTasks } from '@ohos/hvigor-ohos-plugin';
  2. export default {
  3. system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
  4. plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
  5. }

5.obfuscation-rules.txt混淆规则文件

  1. # Define project specific obfuscation rules here.
  2. # You can include the obfuscation configuration files in the current module's build-profile.json5.
  3. #
  4. # For more details, see
  5. # https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
  6. # Obfuscation options:
  7. # -disable-obfuscation: disable all obfuscations
  8. # -enable-property-obfuscation: obfuscate the property names
  9. # -enable-toplevel-obfuscation: obfuscate the names in the global scope
  10. # -compact: remove unnecessary blank spaces and all line feeds
  11. # -remove-log: remove all console.* statements
  12. # -print-namecache: print the name cache that contains the mapping from the old names to new names
  13. # -apply-namecache: reuse the given cache file
  14. # Keep options:
  15. # -keep-property-name: specifies property names that you want to keep
  16. # -keep-global-name: specifies names that you want to keep in the global scope

6.应用级配置信息build-profile.json5文件

  1. {
  2. "app": {
  3. "signingConfigs": [
  4. {
  5. "name": "default",
  6. "type": "HarmonyOS",
  7. "material": {
  8. "certpath": "C:\\Users\\Administrator\\.ohos\\config\\default_HarmonyApp_T1-S6iZ5p-kYEzQIOXqUYs2QX3JtFcQCwPW0T9qQpaU=.cer",
  9. "storePassword": "0000001A1B842713EB4D0EA640734AC141FF59A3959AEFAE0BF8F0C3CAC53A13D7B9BD06AE028D3CDB95",
  10. "keyAlias": "debugKey",
  11. "keyPassword": "0000001A8002906FA9CC8755245FC0169F97D0818626A0A037F70168BB2D75BB3628859BD21E246A96B4",
  12. "profile": "C:\\Users\\Administrator\\.ohos\\config\\default_HarmonyApp_T1-S6iZ5p-kYEzQIOXqUYs2QX3JtFcQCwPW0T9qQpaU=.p7b",
  13. "signAlg": "SHA256withECDSA",
  14. "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\default_HarmonyApp_T1-S6iZ5p-kYEzQIOXqUYs2QX3JtFcQCwPW0T9qQpaU=.p12"
  15. }
  16. }
  17. ],
  18. "products": [
  19. {
  20. "name": "default",
  21. "signingConfig": "default",
  22. "compileSdkVersion": "4.1.0(11)",
  23. "compatibleSdkVersion": "4.1.0(11)",
  24. "runtimeOS": "HarmonyOS",
  25. }
  26. ],
  27. "buildModeSet": [
  28. {
  29. "name": "debug",
  30. },
  31. {
  32. "name": "release"
  33. }
  34. ]
  35. },
  36. "modules": [
  37. {
  38. "name": "entry",
  39. "srcPath": "./entry",
  40. "targets": [
  41. {
  42. "name": "default",
  43. "applyToProducts": [
  44. "default"
  45. ]
  46. }
  47. ]
  48. }
  49. ]
  50. }

7.应用级构建脚本文件hvigorifile.ts

  1. import { appTasks } from '@ohos/hvigor-ohos-plugin';
  2. export default {
  3. system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
  4. plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
  5. }