6 Star 3 Fork 32

OpenHarmony/developtools_global_resource_tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

OpenHarmony资源编译工具

简介

restool(资源编译工具)是一种资源构建工具。通过编译资源文件创建资源索引、解析资源。restool保存在sdk安装目录下的toolchains子目录。

代码目录

/developtools
|----global_resource_tool
|    |----include         #头文件
|    |----src             #源代码文件
|    |----test            #测试用例
|    |----build           #依赖三方库编译脚本  
|    |----BUILD.gn        #编译脚本
|    |----CMakeLists.txt  #CMake文件
|    |----win32.cmake     #Windows交叉编译脚本  

使用说明

SDK编译命令

SDK编译命令参考

参数说明

restool支持的命令选项

选项 是否可缺省 是否存在入参 描述
-i/--inputPath 不可缺省 带参数 指定需要构建的资源目录或者资源中间件。
在资源目录中支持指定一个编译好的Hap资源目录(解压态),在此Hap的基础上完成叠加编译。
-j/--json 不可缺省 带参数 指定config.json或者module.json文件路径。
-o/--outputPath 不可缺省 带参数 指定已编译资源的输出路径。
-p/--packageName 不可缺省 带参数 指定编译资源的bundle名称。
-r/--resHeader 不可缺省 带参数 指定资源的头文件路径,有三种格式:“.txt”、“.js”、“.h”。
-e/--startId 可缺省 带参数 指定生成资源的起始ID值,例如:0x01000000,范围[0x01000000, 0x06FFFFFF),[0x08000000, 0x41FFFFFF)
-f/--forceWrite 可缺省 不带参数 如果输出路径已经存在。强制删除,重新生成。
-h/--help 可缺省 不带参数 查看工具帮助信息。
-m/--modules 可缺省 带参数 多模块联合编译时,指定多个模块名。用“,”连接。
-x/--append 可缺省 带参数 指定生成中间文件的资源目录或单个资源路径。同一个命令可以多次指定。
-z/--combine 可缺省 不带参数 针对资源中间文件目录,生成编译结果。
-v/--version 可缺省 不带参数 查看工具版本号。
-l/--fileList 可缺省 带参数 指定命令选项的集合json文件,例如:resConfig.json。详细格式查看开发文档。
--ids 可缺省 带参数 指定生成id_defined.json的输出目录。
--defined-ids 可缺省 带参数 指定id_defined.json文件路径,一般都是通过--ids生成。
id_defined.json包含资源类型、名称及其ID的列表。
开发者可以自定义id_defined.json中的资源ID。
--dependEntry 可缺省 带参数 FA模型下单独编译feature时,指定entry模块的编译结果目录。
--icon-check 可缺省 不带参数 开启icon和startWindowIcon的PNG图片校验功能。
--target-config 可缺省 带参数 与“-i”命令同时使用,支持选择编译。
具体可参考如下target-config参数说明
--thread 可缺省 带参数 指定资源编译时开启的子线程数量。
--ignored-file 可缺省 带参数 指定资源编译时文件和文件夹的忽略规则,格式为正则表达式,多个规则之间以“:”分隔。例如:“\.git:\.svn”表示忽略名称为“.git”、“.svn”的文件和文件夹。

target-config参数说明

支持参数配置类型:MccMnc、Locale、Orientation、Device、ColorMode、Density

参数格式说明:配置之间用“;”分割,配置中的值用“[]”封装,并使用“,”分割。

MccMnc匹配规则:Mcc(国家码)必须相同;Mnc(网络码)不存在时默认匹配,否则Mnc须相同才匹配。

Locale匹配规则:Locale匹配需满足以下三条规则。

1、语言须相同。

2、脚本(文字)不存在时默认匹配,否则必须相同。

3、国家或地区不存在时默认匹配,否则必须相同。

参数举例说明:Locale[zh_CN,en_US];Device[phone],该参数过滤其他语言,保留能匹配上zh_CN和en_US的语言;过滤其他设备,保留phone;其他参数(如MccMnc、Orientation等)配置不过滤均保留。

restool支持的子命令

命令 描述
dump 以json的格式输出hap包中resource的内容。

dump命令

restool dump [-h] [config] filePath

dump命令参数列表

参数 是否可缺省 是否存在入参 描述
-h 可缺省 不带参数 帮助信息。
config 可缺省 不带参数 只打印hap包中资源的限定词信息。

示例:

# 打印hap包中所有的资源信息
restool dump entry.hap
# 打印hap包中资源的限定词信息
restool dump config entry.hap

使用实例

例如:entry目录结构如下

entry/src/main
|    |----resource
|    |    |----base
|    |    |    |----element
|    |    |    |----media
|    |    |    |----profile
|    |    |----rawfile
|    |----config.json/module.json

构建资源全量命令:

restool -i entry/src/main  -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt -f

构建资源增量命令(仅预览模式可用),具体步骤如下:

1.生成资源中间件:

restool -x entry/src/main/resource -o out

2.编译中间件:

restool -i out1 -i out2 -o out -p com.ohos.demo -r out/ResourceTable.txt -j entry/src/main/module.json -f -z

叠加资源编译命令:

# hapResource为解压后的Hap包路径
restool -i entry/src/main -i hapResource -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt -f

固定资源ID的方式有两种,如下:

方式一:在resource/base/element/目录下存放自定义id_defined.json文件。构建成功后,生成的ID值将会和id_defined.json文件中自定义的ID值保持一致。

方式二:通过--ids 命令生成id_defined.json文件。--defined-ids命令指定id_defined.json文件。构建成功后,生成的ID值将会和id_defined.json文件中自定义的ID值保持一致。

生成id_defined.json文件:

restool -i entry/src/main  -j entry/src/main/module.json -p com.ohos.demo -o out -r out/ResourceTable.txt --ids out -f

指定资源ID固定的id_defined.json文件:

restool -i entry/src/main  -j entry/src/main/module.json -p com.ohos.demo -o out1 -r out1/ResourceTable.txt --defined-ids out/id_defined.json -f

资源类型介绍

资源类型介绍

相关仓

global_resource_tool

third_party_cJSON

third_party_libpng

third_party_bounds_checking_function

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS

简介

OpenHarmony资源编译工具,提供给IDE使用。 展开 收起
README
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/openharmony/developtools_global_resource_tool.git
git@gitee.com:openharmony/developtools_global_resource_tool.git
openharmony
developtools_global_resource_tool
developtools_global_resource_tool
master

搜索帮助