openharmony之一多开发:产品形态配置讲解

OpenHarmony 的“一多开发”指的是 一次开发,多端部署(简称“一多”),即使用 一套代码工程,一次开发上架,按需部署到不同终端设备上

🎯 核心概念速览

产品形态定义

写在前面:

1.不同的形态其实本质差异体现在子系统和部件的差异,openharmony操作系统底层其实屏蔽了不同内核之间的差异,使其2in1(2in1和PC其实是相同的,只是换了称呼)设备类型也可以在TV上运行,在phone/default类型设备也可以运行。
2.vendor目录下的产品形态配置文件(比如vendor\hihope\dayu210\config.json)会根据相同合并、差异覆盖的方式更新productdefine\common\inherit\phone.json。
3.ArkTs即应用层主要体现在: “deviceTypes”: [
“phone”,
“tablet”
] 在这里插入图片描述
4.需要注意是的部分设备形态在低版本的API上是不支持的,其底层通过SysCap能力集合来区分不同的设备差异,当然也可以通过配置使其都支持。
5.不同设备类型通过bundleManager(BMS)安装子系统来进行校验,即HAP所设置的deviceTypes与实际设备类型不符合,是无法安装的。

不同形态编译命令:
方式一:
./build.sh -product-name 2in1_core_system -ccache --device-type=2in1
./build.sh -product-name dayu210 -ccache --device-type=2in1 
仅作参考,实际并不希望随意更改设备类型。(不符合设计规范)
方式二:
hb命令在配置好自己的产品后,执行hb set命令会显示你的定制产品
.hb build -ccache --device-type=2in1

OpenHarmony采用分层解耦的产品定义架构,将产品配置分为三个层次:

层次描述配置位置示例
系统类型基础系统能力base/mini/small/standard
设备形态产品类别模板inherit/phone/tablet/watch
产品实例具体产品配置products/system-arm64-default

系统类型对比表

特性轻量系统(mini)小型系统(small)标准系统(standard)
最小内存128KB1MB128MB
内核类型LiteOS-MLiteOS-A/LinuxLinux
处理器架构Cortex-M/RISC-V 32位Cortex-ACortex-A
图形能力无界面基础GUI完整3D加速
应用框架轻量级JS完整ArkUI
分布式能力基础通信完整软总线全场景协同
典型设备传感器、手环摄像头、路由器手机、平板、车机

📁 源码目录架构

目录结构

productdefine/common/                 [源码根目录]
├── base/                             # 系统类型基础配置
│   ├── mini_system.json             # 轻量系统最小集 [128KB+]
│   ├── small_system.json            # 小型系统最小集 [1MB+]
│   └── standard_system.json         # 标准系统最小集 [128MB+]
├── inherit/                          # 设备形态模板库
│   ├── chipset_common.json          # 芯片通用模板
│   ├── headless.json                # 无头系统模板
│   ├── ipcamera.json                # IPCamera模板
│   ├── phone.json                   # 手机模板 [通话+数据]
│   ├── tablet.json                  # 平板模板 [大屏+触控]
│   ├── wearable.json                # 穿戴设备模板 [低功耗]
│   ├── tv.json                      # 电视模板 [多媒体]
│   ├── 2in1.json                    # 二合一设备模板
│   └── rich.json                    # 全功能模板
└── products/                         # 具体产品配置
    ├── ohos-sdk.json                # SDK产品配置
    ├── system_arm_default.json      # 32位ARM配置
    └── system_arm64_default.json    # 64位ARM配置

🔍 产品形态本质区别分析

1. 系统架构差异

🏗️ 内核架构对比
OpenHarmony内核架构
LiteOS-M
LiteOS-A
Linux
轻量系统
128KB内存
无MMU
实时性优先
小型系统
1MB内存
简化MMU
功耗平衡
标准系统
128MB内存
完整MMU
功能丰富
🎯 系统能力矩阵
能力维度轻量系统小型系统标准系统
进程管理任务调度多进程多用户多进程
内存管理静态分配动态分配虚拟内存
文件系统轻量级FS完整FS多文件系统
网络协议基础TCP/IP完整协议栈全协议支持
图形系统基础GUI3D加速
安全机制基础加密完整安全框架企业级安全

2. 设备形态特性对比

📱 手机形态 (phone.json)

核心特征:

  • 通话能力:完整电话协议栈
  • 移动网络:2G/3G/4G/5G/5G-A/6G支持
  • 位置服务:GPS/北斗/基站定位
  • 传感器:加速度计、陀螺仪、磁力计
  • 相机:前后置摄像头支持
  • 电池管理:精确电量管理

配置片段:

{
  "component": "telephony",
  "features": [
  ]
}
📱 平板形态 (tablet.json)

核心特征:

  • 大屏适配:10-13英寸屏幕优化
  • 触控优化:多点触控、手势识别
  • 分屏多任务:多窗口并行运行
  • 无通话模块:相比手机裁剪电话功能
  • 增强图形:更高分辨率支持

差异化配置:

{
  "inherit": ["productdefine/common/inherit/rich.json"],
  "subsystems": [
    {
      "subsystem": "telephony",// 移除电话功能
      "components": []  
    }
  ]
}
⌚ 穿戴形态 (wearable.json)

核心特征:

  • 超低功耗:深度睡眠模式
  • 健康监测:心率、血氧、步数
  • 小屏适配:1-2英寸圆形/方形屏幕
  • 蓝牙连接:BLE低功耗通信
  • 简化UI:极简交互界面

功耗优化配置:

{
  "component": "power_manager",
  "features": 
  ]
}
📺 电视形态 (tv.json)

核心特征:

  • 大屏显示:55-85英寸4K/8K支持
  • 遥控器:红外/蓝牙遥控
  • 媒体播放:4K视频解码、HDR支持
  • 网络连接:WiFi 6、有线以太网
  • 无触控:纯遥控器操作

媒体能力配置:

{
  "component": "multimedia",
  "features": [
  ]
}

🔧 产品配置详解

配置继承机制

🧬 三层继承架构
基础系统类型
设备形态模板
具体产品配置
standard_system.json
rich.json
phone.json
tablet.json
system_arm64_default.json
phone_product.json
tablet_product.json
⚙️ 配置优先级规则
  1. 高优先级: 产品实例配置
  2. 中优先级: 设备形态模板
  3. 低优先级: 系统类型基础

关键配置字段解析

📋 产品配置文件结构
{
  "version": "3.0",                    // 配置格式版本
  "product_name": "system-arm64-default",  // 产品唯一标识
  "device_company": "ohos",            // 厂商标识
  "target_cpu": "arm64",               // 目标CPU架构 [arm/arm64/x86/riscv]
  "board": "arm64",                    // 开发板型号
  "type": "standard",                  // 系统类型 [mini/small/standard]
  "enable_ramdisk": true,              // 是否启用ramdisk
  "build_selinux": true,               // 是否启用SELinux
  "inherit": ["rich.json"],            // 继承的模板列表
  "subsystems": [...]                 // 子系统配置
}
🎯 CPU架构支持矩阵
CPU架构轻量系统小型系统标准系统典型设备
ARM Cortex-MSTM32、ESP32
ARM Cortex-A树莓派、RK3568
ARM64手机、服务器
RISC-V 32物联网芯片
RISC-V 64开发板

📊 系统能力对比分析

子系统能力矩阵

子系统类别轻量系统小型系统标准系统功能描述
arkui基础版完整版UI框架
telephony基础版完整版电话功能
multimedia基础版完整版多媒体处理
location基础版完整版位置服务
connectivity基础版完整版完整版网络连接
security基础版完整版企业级安全框架
distributed基础版完整版分布式能力

内存占用对比

系统类型最小内存推荐内存存储空间启动时间
轻量系统128KB512KB1MB<1s
小型系统1MB4MB16MB2-5s
标准系统128MB512MB2GB10-30s

🛠️ 实战配置指南

创建新产品形态

步骤1: 选择基础系统类型
# 根据硬件资源选择
- 128KB-512KB内存 → mini_system.json
- 1MB-16MB内存 → small_system.json  
- 128MB+内存 → standard_system.json
步骤2: 选择设备形态模板
# 根据产品类型选择
- 手机 → phone.json
- 平板 → tablet.json
- 手表 → wearable.json
- 电视 → tv.json
- 通用设备 → rich.json
步骤3: 创建产品配置文件
// products/my_product.json
{
  "version": "3.0",
  "product_name": "my-custom-device",
  "device_company": "mycompany",
  "target_cpu": "arm64",
  "board": "myboard",
  "type": "standard",
  "inherit": [
    "productdefine/common/inherit/rich.json",
    "productdefine/common/inherit/phone.json"
  ],
  "subsystems": [
    {
      "subsystem": "custom",
      "components": [
        {
          "component": "my_custom_feature",
          "features": ["custom_feature_enable=true"]
        }
      ]
    }
  ]
}

配置验证流程

✅ 验证步骤
  1. 语法检查: JSON格式验证
  2. 依赖检查: 子系统依赖关系
  3. 内存估算: 内存占用计算
  4. 功能测试: 核心功能验证
🔍 验证工具
# 使用build.sh验证
./build.sh --product-name my_product --check-only

# 查看最终部件列表
cat out/preloader/my_product/parts.json

🔍 配置分析

系统类型详细配置对比

以下是三种系统类型的详细组件对比:

📊 轻量系统 (mini_system.json)
{
  "subsystems": [
    {
      "subsystem": "hiviewdfx",
      "components": [
        "hilog_lite",
        "hievent_lite",
        "hidumper_lite"
      ]
    },
    {
      "subsystem": "startup",
      "components": [
        "bootstrap_lite",
        "appspawn_lite"
      ]
    },
    {
      "subsystem": "communication",
      "components": [
        "dsoftbus",
        "ipc"
      ]
    },
    {
      "subsystem": "security",
      "components": [
        "device_auth",
        "huks_lite"
      ]
    },
    {
      "subsystem": "commonlibrary",
      "components": [
        "utils_lite"
      ]
    },
    {
      "subsystem": "updater",
      "components": [
        "sys_installer_lite"
      ]
    },
    {
      "subsystem": "thirdparty",
      "components": [
        "libcoap",
        "lwip",
        "mbedtls",
        "cJSON",
        "zlib",
        "libboundscheck",
        "cmsis",
        "nvram"
      ]
    }
  ]
}
📊 小型系统 (small_system.json)
{
  "subsystems": [
    {
      "subsystem": "hdf",
      "components": [
        "hdf_core",
        "hdf_driver_framework",
        "hdf_device_desc",
        "hdf_config_manager",
        "hdf_platform"
      ]
    },
    {
      "subsystem": "kernel",
      "components": [
        "liteos_a"
      ]
    },
    {
      "subsystem": "hiviewdfx",
      "components": [
        "hilog_lite",
        "hievent_lite",
        "hidumper_lite"
      ]
    },
    {
      "subsystem": "startup",
      "components": [
        "bootstrap_lite",
        "appspawn_lite",
        "init_lite"
      ]
    },
    {
      "subsystem": "communication",
      "components": [
        "dsoftbus",
        "ipc",
        "samgr_lite"
      ]
    },
    {
      "subsystem": "security",
      "components": [
        "device_auth",
        "huks_lite",
        "access_token_lite"
      ]
    },
    {
      "subsystem": "commonlibrary",
      "components": [
        "c_utils",
        "utils_lite"
      ]
    },
    {
      "subsystem": "updater",
      "components": [
        "sys_installer_lite"
      ]
    },
    {
      "subsystem": "thirdparty",
      "components": [
        "libcoap",
        "lwip",
        "mbedtls",
        "cJSON",
        "zlib",
        "libboundscheck",
        "cmsis",
        "nvram",
        "musl",
        "libffi"
      ]
    }
  ]
}
📊 标准系统 (standard_system.json)
{
  "subsystems": [
    {
      "subsystem": "hdf",
      "components": [
        "hdf_core",
        "hdf_driver_framework",
        "hdf_device_desc",
        "hdf_config_manager",
        "hdf_platform",
        "hdf_usb"
      ]
    },
    {
      "subsystem": "communication",
      "components": [
        "ipc",
        "dsoftbus",
        "net_manager"
      ]
    },
    {
      "subsystem": "systemabilitymgr",
      "components": [
        "samgr",
        "safwk"
      ]
    },
    {
      "subsystem": "hiviewdfx",
      "components": [
        "hilog",
        "hitrace",
        "hidumper",
        "hievent",
        "hisysevent",
        "hiview",
        "faultloggerd"
      ]
    },
    {
      "subsystem": "security",
      "components": [
        "access_token",
        "huks",
        "deviceauth",
        "selinux_adapter",
        "dataclassification",
        "iam"
      ]
    },
    {
      "subsystem": "commonlibrary",
      "components": [
        "c_utils",
        "memory_utils"
      ]
    },
    {
      "subsystem": "updater",
      "components": [
        "update_service",
        "update_engine"
      ]
    },
    {
      "subsystem": "developtools",
      "components": [
        "hdc",
        "hidumper",
        "hitrace"
      ]
    },
    {
      "subsystem": "thirdparty",
      "components": [
        "mbedtls",
        "openssl",
        "zlib",
        "jsoncpp",
        "libxml2",
        "libcurl",
        "cares",
        "nghttp2",
        "libffi",
        "libunwind",
        "libcxx",
        "libcxxabi",
        "compiler_rt",
        "libc",
        "musl",
        "e2fsprogs",
        "f2fs-tools",
        "exfatprogs",
        "dosfstools"
      ]
    }
  ]
}

设备形态配置详解

🖥️ 无头系统 (headless.json)

专为无显示界面的设备设计,如服务器、网关:

{
  "version": "3.0",
  "subsystems": [
    {
      "subsystem": "build",
      "components": [
        "build_framework"
      ]
    },
    {
      "subsystem": "startup",
      "components": [
        "startup_l2",
        "init",
        "appspawn"
      ]
    },
    {
      "subsystem": "hiviewdfx",
      "components": [
        "hilog",
        "hitrace",
        "hidumper",
        "hievent",
        "hisysevent",
        "hiview",
        "faultloggerd"
      ]
    },
    {
      "subsystem": "distributedhardware",
      "components": [
        "device_manager"
      ]
    },
    {
      "subsystem": "security",
      "components": [
        "device_auth",
        "huks",
        "access_token",
        "selinux_adapter",
        "dataclassification",
        "iam"
      ]
    },
    {
      "subsystem": "account",
      "components": [
        "os_account"
      ]
    },
    {
      "subsystem": "communication",
      "components": [
        "ipc",
        "dsoftbus",
        "net_manager",
        "bluetooth"
      ]
    },
    {
      "subsystem": "ability",
      "components": [
        "ability_runtime",
        "ability_base",
        "abilityms",
        "ability_manager",
        "abilityms_client"
      ]
    },
    {
      "subsystem": "arkui",
      "components": [
        "napi"
      ]
    }
  ]
}
📹 IPCamera (ipcamera.json)

专为网络摄像头设计,集成多媒体能力:

{
  "version": "3.0",
  "subsystems": [
    {
      "subsystem": "arkui",
      "components": [
        "ace_engine",
        "napi"
      ]
    },
    {
      "subsystem": "account",
      "components": [
        "os_account"
      ]
    },
    {
      "subsystem": "distributeddatamgr",
      "components": [
        "preferences",
        "kv_store",
        "relational_store",
        "data_storage",
        "distributeddata"
      ]
    },
    {
      "subsystem": "filemanagement",
      "components": [
        "user_file_service",
        "file_api",
        "storage_manager",
        "filemanagement_libn"
      ]
    },
    {
      "subsystem": "security",
      "components": [
        "appverify",
        "deviceauth",
        "huks",
        "access_token",
        "selinux_adapter",
        "dataclassification"
      ]
    },
    {
      "subsystem": "hdf",
      "components": [
        "hdf_core",
        "hdf_driver_framework",
        "hdf_device_desc",
        "hdf_config_manager",
        "hdf_platform",
        "hdf_usb",
        "hdf_input",
        "hdf_display",
        "hdf_sensor",
        "hdf_audio",
        "hdf_camera"
      ]
    },
    {
      "subsystem": "multimedia",
      "components": [
        "camera_framework",
        "camera_standard",
        "media_standard",
        "audio_standard",
        "image_standard"
      ]
    },
    {
      "subsystem": "thirdparty",
      "components": [
        "curl",
        "mbedtls",
        "openssl",
        "zlib",
        "jsoncpp",
        "libxml2",
        "libyuv",
        "libjpeg_turbo",
        "libpng",
        "libwebp",
        "ffmpeg",
        "alsa_lib"
      ]
    }
  ]
}

配置字段深度解析

🔧 关键配置字段说明
字段名数据类型必填说明示例值
versionstring配置格式版本“3.0”
product_namestring产品唯一标识符“my_custom_device”
device_companystring厂商代码“hisilicon”
target_cpustringCPU架构“arm64/arm/x86/riscv”
boardstring开发板型号“hi3516dv300”
typestring系统类型“standard/small/mini”
enable_ramdiskboolean启用ramdisk加速true/false
build_selinuxboolean启用SELinux安全true/false
inheritarray继承的模板列表[“rich.json”, “phone.json”]
subsystemsarray子系统配置数组[…]
🎯 子系统配置结构
{
  "subsystems": [
    {
      "subsystem": "arkui",           // 子系统名称
      "components": [                  // 组件列表
        {
          "component": "ace_engine",   // 组件名称
          "features": [                // 特性配置 (可选)
          ]
        }
      ]
    }
  ]
}

高级配置技巧

🔄 动态配置继承
{
  "inherit": [
    "productdefine/common/base/standard_system.json",
    "productdefine/common/inherit/rich.json",
    "productdefine/common/inherit/phone.json"
  ],
  "subsystems": [
    {
      "subsystem": "telephony",
      "components": [
        {
          "component": "cellular_call",
          "features": [
            "5g_support=true",
            "volte_enable=true"
          ]
        }
      ]
    }
  ]
}
⚙️ 条件编译配置
{
  "subsystems": [
    {
      "subsystem": "graphic",
      "components": [
        {
          "component": "graphic_2d",
          "features": [
            "gpu_acceleration=false",
            "gpu_acceleration=true",
          ]
        }
      ]
    }
  ]
}

最佳实践案例

📱 创建自定义手机产品

场景: 基于标准系统创建一款中低端4G手机

  1. 基础配置 (products/my_phone.json):
{
  "version": "3.0",
  "product_name": "my-4g-phone",
  "device_company": "mycorp",
  "target_cpu": "arm",
  "board": "mt6765",
  "type": "standard",
  "enable_ramdisk": true,
  "build_selinux": true,
  "inherit": [
    "productdefine/common/base/standard_system.json",
    "productdefine/common/inherit/phone.json"
  ],
  "subsystems": [
    {
      "subsystem": "telephony",
      "components": [
        {
          "component": "cellular_call",
          "features": [
          ]
        }
      ]
    },
    {
      "subsystem": "multimedia",
      "components": [
        {
          "component": "camera_standard",
          "features": [
          ]
        }
      ]
    }
  ]
}
  1. 内存优化配置:
{
  "subsystems": [
    {
      "subsystem": "graphic",
      "components": [
        {
          "component": "graphic_2d",
          "features": [
            "gpu_acceleration=true",
            "memory_optimization=aggressive"
          ]
        }
      ]
    }
  ]
}
⌚ 创建智能手表产品

场景: 基于小型系统创建低功耗智能手表

{
  "version": "3.0",
  "product_name": "my-smartwatch",
  "device_company": "mycorp",
  "target_cpu": "arm",
  "board": "nrf52840",
  "type": "small",
  "enable_ramdisk": false,
  "build_selinux": false,
  "inherit": [
    "productdefine/common/base/small_system.json",
    "productdefine/common/inherit/wearable.json"
  ],
  "subsystems": [
    {
      "subsystem": "sensors",
      "components": [
        "accelerometer",
        "gyroscope",
        "heart_rate_sensor"
      ]
    },
    {
      "subsystem": "powermgr",
      "components": [
        {
          "component": "power_manager",
          "features": [
            "low_power_mode=extreme",
            "always_on_display=true"
          ]
        }
      ]
    }
  ]
}
🚨 常见错误及解决方案
错误类型错误信息根因分析解决方案
JSON格式错误Expecting ‘,’ delimiter缺少逗号或括号使用JSON验证工具
依赖缺失Component ‘xxx’ not found未包含所需子系统检查inherit配置
内存溢出Out of memory组件过多或配置过大裁剪不必要的组件
架构不匹配CPU arch incompatibletarget_cpu配置错误检查CPU架构设置
权限错误Permission deniedSELinux配置问题调整安全策略

配置模板速查表

📋 快速配置模板
设备类型基础系统推荐模板关键特性
智能手机standardphone.json + rich.json通话、4G/5G、相机
平板电脑standardtablet.json + rich.json大屏、无通话
智能手表smallwearable.json低功耗、健康监测
智能电视standardtv.json + rich.json4K视频、遥控器
IPCamerastandardipcamera.json视频采集、网络传输
IoT网关smallheadless.json无界面、网络功能
开发板standardrich.json全功能、开发调试

📚 附录:源码文件清单

📁 基础系统类型文件
productdefine/common/base/
├── mini_system.json        # 轻量系统 - 128KB内存
├── small_system.json       # 小型系统 - 1MB内存  
└── standard_system.json    # 标准系统 - 128MB内存
📁 设备形态模板文件
productdefine/common/inherit/
├── rich.json              # 全功能模板
├── phone.json             # 手机专用模板
├── tablet.json            # 平板专用模板
├── wearable.json          # 穿戴设备模板
├── tv.json                # 智能电视模板
├── 2in1.json              # 二合一设备模板
├── headless.json          # 无头系统模板
├── ipcamera.json          # 网络摄像头模板
└── chipset_common.json    # 芯片通用模板
📁 产品配置示例
productdefine/common/products/
├── ohos-sdk.json              # SDK产品配置
├── system_arm_default.json    # 32位ARM系统
├── system_arm64_default.json  # 64位ARM系统
├── system_riscv32.json        # 32位RISC-V系统
└── system_riscv64.json        # 64位RISC-V系统

📊 组件统计对比表

系统类型子系统数量组件总数第三方库典型内存占用
mini_system725+8个128KB-512KB
small_system935+11个1MB-16MB
standard_system1050+20个128MB-512MB
rich.json2380+40+512MB+
phone.json25+100+45+1GB+

🎯 实际应用建议

选择系统类型的决策树
硬件资源评估:
├── 内存 < 1MB → mini_system.json
├── 内存 1-128MB → small_system.json
└── 内存 >= 128MB → standard_system.json

功能需求评估:
├── 需要完整UI → standard + rich.json
├── 需要通话功能 → standard + phone.json
├── 需要穿戴功能 → small + wearable.json
└── 需要摄像头 → standard + ipcamera.json
内存优化检查清单
  • 移除不必要的子系统
  • 禁用GPU加速 (gpu_acceleration=false)
  • 减少第三方库依赖
  • 使用轻量级组件 (xxx_lite)
  • 启用内存压缩 (memory_compression=true)
  • 调整缓存大小 (cache_size=small)
编译验证流程

# 完整编译
./build.sh --product-name my_product --ccahe

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值