{"id":29353642,"url":"https://github.com/frankplus/oniro_openharmony_build","last_synced_at":"2025-07-09T02:08:22.601Z","repository":{"id":265488116,"uuid":"761222248","full_name":"frankplus/oniro_openharmony_build","owner":"frankplus","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-21T13:26:16.000Z","size":42356,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"OpenHarmony-4.0-Release","last_synced_at":"2025-07-01T16:10:09.762Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frankplus.png","metadata":{"files":{"readme":"README_zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-21T13:22:13.000Z","updated_at":"2024-06-25T03:24:30.000Z","dependencies_parsed_at":"2024-11-29T16:03:17.057Z","dependency_job_id":"646cdd9d-f715-4326-b0de-e76e430bf1be","html_url":"https://github.com/frankplus/oniro_openharmony_build","commit_stats":null,"previous_names":["frankplus/oniro_openharmony_build"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/frankplus/oniro_openharmony_build","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankplus%2Foniro_openharmony_build","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankplus%2Foniro_openharmony_build/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankplus%2Foniro_openharmony_build/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankplus%2Foniro_openharmony_build/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frankplus","download_url":"https://codeload.github.com/frankplus/oniro_openharmony_build/tar.gz/refs/heads/OpenHarmony-4.0-Release","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankplus%2Foniro_openharmony_build/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264379205,"owners_count":23598823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-09T02:08:20.872Z","updated_at":"2025-07-09T02:08:22.574Z","avatar_url":"https://github.com/frankplus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 编译构建\u003ca name=\"ZH-CN_TOPIC_0000001124588563\"\u003e\u003c/a\u003e\n\n-   [简介](#section11660541593)\n-   [目录](#section161941989596)\n-   [约束与限制](#section2029921310472)\n-   [说明](#section1312121216216)\n-   [常见问题说明](#section131336181)\n-   [相关仓](#section1371113476307)\n\n## 简介\u003ca name=\"section11660541593\"\u003e\u003c/a\u003e\n\n编译构建子系统提供了一个基于Gn和ninja的编译构建框架。\n\n根据产品配置，编译生成对应的镜像包。其中编译构建流程为：\n\n1.  使用Gn配置构建目标。\n2.  Gn运行后会生成ninja文件。\n3.  通过运行ninja来执行编译任务。\n\n**图 1**  编译构建子系统架构图\u003ca name=\"fig16488143010409\"\u003e\u003c/a\u003e  \n![](docs/figures/build_framework_ZN.png \"编译构建子系统架构图\")\n\n## 目录\u003ca name=\"section161941989596\"\u003e\u003c/a\u003e\n\n```\n/build                           # 编译构建主目录\n\n├── __pycache__                   \n├── build_scripts/                # 编译相关的python脚本\n├── common/                       \n├── config/                       # 编译相关的配置项\n├── core\n│   ├── gn/                       # 编译入口BUILD.gn配置\n│   └── build_scripts/            \n├── docs                          \n├── gn_helpers.py*                \n├── lite/                         # hb和preloader入口                      \n├── misc/                         \n├── ohos                          # OpenHarmony编译打包流程配置\n│   ├── kits                      # kits编译打包模板和处理流程\n│   ├── ndk                       # ndk模板和处理流程\n│   ├── notice                    # notice模板和处理流程\n│   ├── packages                  # 版本打包模板和处理流程\n│   ├── sa_profile                # sa模板和处理流程\n│   ├── sdk                       # sdk模板和处理流程，包括sdk中包含的模块配置\n│   └── testfwk                   # 测试相关的处理\n├── ohos.gni*                     # 汇总了常用的gni文件，方便各个模块一次性import\n├── ohos_system.prop              \n├── ohos_var.gni*                 \n├── prebuilts_download.sh*        # 预编译脚本\n├── print_python_deps.py*         \n├── scripts/                      \n├── subsystem_config.json         \n├── subsystem_config_example.json \n├── templates/                    # c/c++编译模板定义\n├── test.gni*                     \n├── toolchain                     # 编译工具链配置\n├── tools                         # 常用工具\n├── version.gni                   \n├── zip.py*                       \n```\n\n## 约束与限制\u003ca name=\"section2029921310472\"\u003e\u003c/a\u003e\n\n-   编译环境需要Ubuntu18.04及以上版本。\n\n-   安装编译所需的程序包。\n\n    安装命令：\n\n    ```\n    sudo apt-get install bison ccache default-jdk flex gcc-arm-linux-gnueabi gcc-arm-none-eabi  genext2fs liblz4-tool libssl-dev libtinfo5 mtd-utils mtools openssl ruby scons unzip u-boot-tools  zip\n    ```\n    \n\n\n## 说明\u003ca name=\"section1312121216216\"\u003e\u003c/a\u003e\n\n**代码根目录下执行全量版本的编译命令**\n\n    ```\n    ./build.sh --product-name {product_name}\n    ```\n\n    编译结果镜像输出在 out/${device_name}/packages/phone/images/目录下。\n\n**编译命令支持选项**\n\n    ```\n    -h, --help                                        # 显示帮助信息并退出\n    --source-root-dir=SOURCE_ROOT_DIR                 # 指定路径\n    --product-name=PRODUCT_NAME                       # 指定产品名\n    --device-name=DEVICE_NAME                         # 指定装置名称\n    --target-cpu=TARGET_CPU                           # 指定cpu\n    --target-os=TARGET_OS                             # 指定操作系统\n    -T BUILD_TARGET, --build-target=BUILD_TARGET      # 指定编译目标，可以指定多个\n    --gn-args=GN_ARGS                                 # gn参数，支持指定多个\n    --ninja-args=NINJA_ARGS                           # ninja参数，支持指定多个\n    -v, --verbose                                     # 生成时显示所有命令行\n    --keep-ninja-going                                # 让ninja持续到1000000个工作失败\n    --jobs=JOBS                                       # 指定编译线程数\n    --export-para=EXPORT_PARA\n    --build-only-gn                                   # 只做gn解析，不运行ninja\n    --ccache                                          # 可选  编译使用ccache，需要本地安装ccache\n    --fast-rebuild                                    # 快速重建，default=False\n    --log-level=LOG_LEVEL                             # 指定编译期间的日志级别'，'三个级别可选：debug, info and error，default='info'\n    --device-type=DEVICE_TYPE                         # 指定设备类型，default='default'\n    --build-variant=BUILD_VARIANT                     # 指定设备操作模式，default='user'\n    ```\n\n**配置文件说明**\n\nOpenHarmony的配置文件主要有四个。\n\n1.  每个模块对应的BUILD.gn文件。\n    可以使用提供的模板，也可以使用gn语法规则自定义编写。\n    \n    **例子：**\n\n    _ohos\\_shared\\_library示例：_\n\n    ```\n    import(\"//build/ohos.gni\")\n    ohos_shared_library(\"helloworld\") {\n      sources = []\n      include_dirs = []\n      cflags = []\n      cflags_c = []\n      cflags_cc = []\n      ldflags = []\n      configs = []\n      deps =[]  # 部件内模块依赖\n    \n      # 跨部件模块依赖定义，\n      # 定义格式为 \"部件名:模块名称\"\n      # 这里依赖的模块必须是依赖的部件声明在inner_kits中的模块\n      external_deps = [\n        \"part_name:module_name\",\n      ]\n    \n      output_name = \"\"           # 可选，模块输出名\n      output_extension = \"\"      # 可选，模块名后缀\n      module_install_dir = \"\"    # 可选，缺省在/system/lib64或/system/lib下， 模块安装路径，模块安装路径，从system/，vendor/后开始指定\n      relative_install_dir = \"\"  # 可选，模块安装相对路径，相对于/system/lib64或/system/lib；如果有module_install_dir配置时，该配置不生效\n      install_images = []        # 可选，缺省值system，指定模块安装到那个分区镜像中，可以指定多个\n    \n      part_name = \"\" # 必选，所属部件名称\n    }\n    ```\n\n    _ohos\\_executable示例：_\n\n    ohos\\_executable模板属性和ohos\\_shared\\_library基本一致\n\n    _注意：可执行模块（即ohos\\_executable模板定义的）默认是不安装的，如果要安装，需要指定install\\_enable = true_\n\n    _ohos\\_prebuilt\\_etc示例：_\n\n    ```\n    import(\"//build/ohos.gni\")\n    ohos_prebuilt_etc(\"etc_file\") {\n      source = \"file\"\n      deps = []                 # 部件内模块依赖\n      module_install_dir = \"\"   #可选，模块安装路径，从system/，vendor/后开始指定\n      relative_install_dir = \"\" #可选，模块安装相对路径，相对于system/etc；如果有module_install_dir配置时，该配置不生效\n      install_images = []       # 可选，缺省值system，指定模块安装到那个分区镜像中，可以指定多个\n      part_name = \"\"            # 必选，所属部件名称\n    }\n    ```\n    更多详细的模板信息请参照[模块配置规则](https://gitee.com/openharmony/docs/tree/master/zh-cn/device-dev/subsystems/subsys-build-module.md#模块配置规则)。\n\n2. 子系统中bundle.json文件或者ohos.build(看子系统具体支持哪一个，后续将全部用bundle.json)\n    \n    **bundle.json**\n\n    ```\n    {\n       \"name\": \"@ohos/\u003ccomponent_name\u003e\",                 # HPM部件英文名称，格式\"@组织/部件名称\"\n       \"description\": \"xxxxxxxxxxxxxxxxxxx\",             # 部件功能一句话描述\n       \"version\": \"3.1\",                                 # 版本号，版本号与OpenHarmony版本号一致\n       \"license\": \"MIT\",                                 # 部件License\n       \"publishAs\": \"code-segment\",                      # HPM包的发布方式，当前默认都为code_segment\n       \"segment\": {\n           \"destPath\": \"\"\n       },                                                # 发布类型为code_segment时为必填项，定义发布类型code_segment的代码还原路径（源码路径）\n       \"dirs\": {},                                       # HPM包的目录结构，字段必填内容可以留空\n       \"scripts\": {},                                    # HPM包定义需要执行的脚本，字段必填，值非必填\n       \"licensePath\": \"COPYING\",\n       \"readmePath\": {\n           \"en\": \"README.rst\"\n       },\n       \"component\": {                                    # 部件属性\n           \"name\": \"\u003ccomponent_name\u003e\",                   # 部件名称\n           \"subsystem\": \"\",                              # 部件所属子系统\n           \"syscap\": [],                                 # 部件为应用提供的系统能力\n           \"features\": [],                               # 部件对外的可配置特性列表，一般与build中的sub_component对应，可供产品配置\n           \"adapted_system_type\": [],                    # 轻量(mini)小型(small)和标准(standard)，可以是多个\n           \"rom\": \"xxxKB\"                                # ROM基线，没有基线写当前值\n           \"ram\": \"xxxKB\",                               # RAM基线，没有基线写当前值\n           \"deps\": {\n               \"components\": [],                         # 部件依赖的其他部件\n               \"third_party\": []                         # 部件依赖的三方开源软件\n           },\n           \"build\": {                                    # 编译相关配置\n               \"sub_component\": [\"部件包含模块的gn目标\"],  # 部件编译入口，新增模块在此处配置\n               \"inner_kits\": [],                         # 部件间接口\n               \"test\": []                                # 部件测试用例编译入口\n           }\n       }\n    }\n    ```\n    bundle.json文件定义了子系统包含的部件。每个部件定义它所包含的模块目标component.build.sub_component，以及部件间交互的接口component.build.inner_kits，\n    测试用例component.build.test_list。部件包含的 模块目标component.build.sub_component是必须要说明的。\n\n    **ohos.build**\n    ```\n    {\n    \"parts\": {\n      \"napi\": {\n        \"module_list\": [\n          \"//foundation/arkui/napi:napi_packages\"              # 部件包含模块的gn目标\n        ],\n        \"inner_kits\": [                                        # 部件间接口\n        ],\n        \"test_list\": [                                         # 测试用例\n          \"//foundation/arkui/napi:napi_packages_test\",\n          \"//foundation/arkui/napi/test/unittest:unittest\"\n        ]\n      }\n\n      \"新增部件名\": {\n        \"module_list\": [\n          \"部件包含的gn目标\"                                    # 部件包含模块的gn目标\n        ],\n        \"inner_kits\": [                                        # 部件间接口\n        ],\n        \"test_list\": [                                         # 测试用例\n          \"包含的测试用例\",\n        ]\n      }\n    }\n    ......\n    \"subsystem\": \"ace\",                                        # 所属子系统\n    }\n    ```\n    ohos.build文件包含两个部分，subsystem部分说明了子系统的名称，parts部分定义了该子系统包含的部件，要添加一个部件，需要把该部件对应的内容添加进parts中去。添加的时候需要指明该部件包含的模块module_list，假如有提供给其它部件的接口，需要在inner_kits中说明，假如有测试用例，需要在test_list中说明，inner_kits与test_list没有也可以不添加。\n\n    这两个文件均在对应的子系统根目录下，新增模块均在指定的目录下新增模块的gn目标即可，如果要新增一个部件，则需要在部件目录中新建一个bundle.json或者ohos.build，然后再在//vendor/{product_company}/{product-name}/config.json中添加对应的部件，直接添加到原有部件后即可。具体流程请参照编译构建指导的[配置规则](https://gitee.com/openharmony/docs/tree/master/zh-cn/device-dev/subsystems/subsys-build-all.md#配置规则)与[新增并编译不同配置](https://gitee.com/openharmony/docs/tree/master/zh-cn/device-dev/subsystems/subsys-build-all.md#新增并编译不同配置)，其中详细的介绍了如何添加一个模块、部件或者子系统。\n\n    成功添加验证：\n    - 在输出文件夹的对应子系统文件夹下的部件文件夹下的BUILD.gn文件中module_list包含了新建模块的BUILD.gn中定义的目标。\n    - 编译完成后打包到image中去，生成对应的so文件或者二进制文件。\n\n\n3. vendor\\产品厂商\\产品名\\config.json\n\n    ```\n    {\n      \"product_name\": \"MyProduct\",\n      \"version\": \"3.0\",\n      \"type\": \"standard\",\n      \"target_cpu\": \"arm\",\n      \"ohos_version\": \"OpenHarmony 1.0\",\n      \"device_company\": \"MyProductVendor\",\n      \"board\": \"MySOC\",\n      \"enable_ramdisk\": true,\n      \"subsystems\": [\n        {\n          \"subsystem\": \"ace\",\n          \"components\": [\n            { \"component\": \"ace_engine_lite\", \"features\":[\"\"] }\n          ]\n        }，\n        ...\n      ]\n    }\n    ```\n    指明了产品名，产品厂商，产品设备，版本，要编译的系统类型，以及产品包含的子系统。\n\n4. build目录下的subsystem_config.json文件。\n\n    ```\n    {\n      \"arkui\": {\n       \"path\": \"foundation/arkui\",\n       \"name\": \"arkui\"\n      },\n      \"ai\": {\n       \"path\": \"foundation/ai\",\n       \"name\": \"ai\"\n      },\n \t  ......\n    }\n    ```\n    该文件对子系统进行了说明，我们需要该子系统定义中的name与path，分别表示子系统的名称和所在文件夹路径。\n\n**ohos-sdk编译**\n\n    **编译命令：**\n\n    ``` ./build.sh --product-name ohos-sdk --ccache ```\n\n    **结果输出：**\n\n    ``` out/sdk/packages/ohos-sdk/ ```\n\n    **ohos-sdk模块配置：**\n\n    ``` build/ohos/sdk/ohos_sdk_description_std.json ```\n\n\n\n## 常见问题说明\u003ca name=\"section131336181\"\u003e\u003c/a\u003e\n\n**如何将一个模块编译并打包到版本中？**\n\n-   模块要指定part\\_name，指定它归属的部件，一个模块只能属于一个部件；\n-   部件的模块，要在部件配置的module\\_list中，或者可以被module\\_list中的模块依赖到；\n-   部件要加到对应产品的部件列表中；\n\n[FAQ](docs/FAQ.md)\n\n[关于deps和external_deps的使用](docs/关于deps及external_deps的使用.md)\n\n[标准系统如何添加一个模板并参与编译](docs/标准系统如何添加一个模块.md)\n\n[标准系统如何修改镜像文件的打包参数](docs/标准系统如何修改镜像文件的打包参数.md)\n\n[如何跟随系统使用gn编译hap](docs/how-to-build-a-hap.md)\n\n[开源软件Notice收集策略说明](docs/开源软件Notice收集策略说明.md)\n\n[关于生成开源软件包](docs/生成开源软件包.md)\n\n[构建系统编码规范与最佳实践](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-build-gn-coding-style-and-best-practice.md)\n\n[部件化编译最佳实践](docs/部件化编译最佳实践.md)\n\n\n## 相关仓\u003ca name=\"section1371113476307\"\u003e\u003c/a\u003e\n\n**[编译构建子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/编译构建子系统.md)**\n\n**[build\\_lite](https://gitee.com/openharmony/build_lite/blob/master/README_zh.md)**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankplus%2Foniro_openharmony_build","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrankplus%2Foniro_openharmony_build","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankplus%2Foniro_openharmony_build/lists"}