贡献 OpenHarmony 库关键配置 #自研框架#ArkUI-X#三方框架#OpenHarmony#HarmonyOS
创建第三方库
- 打开 DevEco Studio 创建一个项目,然后创建一个库模块,选择 static library。详细步骤可参考:开发静态共享包。
在项目内会生成 library 文件夹
- 对所创建的库模块进行开发,需要完善库模块中生成的 oh-package.json5 文件,有关三方库名称的规则,请参阅三方库名称指南章节,其他配置项的设置请参考 oh-package.json5 配置说明。
目录分析
library // HAR根目录
├─libs // 存放用户自定义引用的Native库,一般为.so文件f
└─src
│ └─main
│ ├─cpp
│ │ ├─types // 定义Native API对外暴露的接口
│ │ │ └─liblibrary
│ │ │ ├─index.d.ts
│ │ │ └─oh-package.json5
│ │ ├─CMakeLists.txt // CMake配置文件
│ │ └─napi_init.cpp // C++源码文件
│ └─ets // ArkTS源码目录
│ │ └─components
│ │ └─MainPage.ets
│ ├─resources // 资源目录,用于存放资源文件,如图片、多媒体、字符串等
│ └─module.json5 // 模块配置文件,包含当前HAR的配置信息
├─build-profile.json5 // Hvigor编译构建所需的配置文件,包含编译选项
├─hvigorfile.ts // Hvigor构建脚本文件,包含构建当前模块的插件、自定义任务等
├─Index.ets // HAR的入口文件,一般作为出口定义HAR对外提供的函数、组件等
└─oh-package.json5 // HAR的描述文件,定义HAR的基本信息、依赖项等
library/build-profile.json5 建议开启代码混淆
{
"apiType": "stageMode",
"buildOption": {},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
// 混淆相关参数
"obfuscation": {
"ruleOptions": {
// true表示进行混淆,false表示不进行混淆。5.0.3.600及以上版本默认为false
"enable": true,
// 混淆规则文件
"files": ["./obfuscation-rules.txt"]
},
// consumerFiles中指定的混淆配置文件会在构建依赖这个library的工程或library时被应用
"consumerFiles": ["./consumer-rules.txt"]
}
}
}
],
"targets": [
{
"name": "default"
}
]
}
build-profile.json5 设置 useNormalizedOHMUrl
{
"app": {
"products": [
{
"buildOption": {
"strictMode": {
"useNormalizedOHMUrl": false
}
}
}
]
}
}
- 在库模块的根目录中,创建一个 README.md(不区分大小写) 文件,描述您三方库的代码以及如何使用它,文件不能为空。
README.md 模板
# feilongui
FeilongUI 是一款功能丰富、高效易用的 UI 库,旨在帮助开发者快速构建美观、交互流畅的用户界面。以下是该库的详细使用指南。
## 安装命令
README.md 中未包含安装命令会导致审核失败
`ohpm install feilongui`
## 模块介绍
README.md 中缺少简要的三方库使用说明会导致审核失败
没有文件会报错
ohpm ERROR: HttpCode 400 The OHPM package must contain a non-empty readme.md file.
ohpm ERROR: Publish failed, detail: The "Publish" request to url "https://ohpm.openharmony.cn/ohpm/feilongui" has failed
- 在库模块的根目录中,创建一个 CHANGELOG.md 文件,描述您三方库的代码不同版本的变更内容,文件不能为空。
没有文件会报错
ohpm ERROR: HttpCode 400 The OHPM package must contain a non-empty changelog.md file.
ohpm ERROR: Publish failed, detail: The "Publish" request to url "https://ohpm.openharmony.cn/ohpm/feilongui" has failed
Changelog.md模板(CHANGELOG.md中未包含当前版本,也就是oh-package.json5中version值的版本。 CHANGELOG.md由清晰的版本号和该版本的修改内容组成,修改内容不可为空,不然过不了审核)
# Changelog
## 1.0.0
\*\*
Unreleased
Added
- 新增 [按钮],用于 [点击]。
Changed
- 优化 [模块 / 功能名称] 的性能,提升 [具体指标,如响应速度、加载时间等]。
Deprecated
- 标记 [某接口 / 方法 / 功能] 为废弃,计划在 [具体版本] 中移除。
Removed
- 移除不再维护的 [某功能 / 模块]。
Fixed
- 修复 [问题描述] 导致的 [具体错误,如程序崩溃、数据错误等]。
Security
- 修复 [名称] 提升系统安全性。
- 在库模块的根目录中,创建一个 LICENSE(不区分大小写) 文件,指定该软件包可以在什么样的许可下被使用、修改和共享,文件不能为空。
许可证模板(LICENSE文件中许可证条款内容和oh-package.json5文件中许可证名称不一致会审核失败) 许可证获取地址
Copyright [此处填写年份,如2025] [此处填写在library/oh-package.json5中的name,否则审核失败]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
没有 LICENSE 文件会报错
ohpm ERROR: HttpCode 400 The OHPM package must contain a non-empty license file.
ohpm ERROR: Publish failed, detail: The "Publish" request to url "https://ohpm.openharmony.cn/ohpm/feilongui" has failed
- 在进行 publish 发布前,请先确保在 OpenHarmony 三方库中心仓上已经创建了帐号,且利用工具 ssh-keygen 生成公、私钥文件 认证管理地址
ssh-keygen -m PEM -t RSA -b 4096 -f ~/.ssh_ohpm/mykey
ohpm config set key_path ~/.ssh_ohpm/mykey
不签名发布时会报错
ohpm ERROR: Publish failed, detail: The "key_path" is empty - configure "key_path" in the .ohpmrc file.
不设置密码发布时会报错
ohpm ERROR: Private key without passphrase is not supported.
ohpm ERROR: You must config a encrypted private key using a non-empty passphrase.
ohpm ERROR: Publish failed, detail: Not supported private key.
不上传公钥(~/.ssh_ohpm/mykey.pub)会报错
ohpm ERROR: HttpCode 400 The publicKey verify failed!
ohpm ERROR: Publish failed, detail: The "Login" request to url "https://ohpm.openharmony.cn/ohpm/login" has failed
- 设置 publish_id
不设置 publish_id 会报错
ohpm ERROR: Publish failed, detail: The "publish_id" is empty - configure "publish_id" in .ohpmrc file.
publish_id 设置错误会报错
ohpm ERROR: HttpCode 400 The publishId is invalid!
ohpm ERROR: Publish failed, detail: The "Login" request to url "https://ohpm.openharmony.cn/ohpm/login" has failed
发布后再发布不更新版本号会报错
ohpm ERROR: HttpCode 400 The OHPM package version already exists.
ohpm ERROR: Publish failed, detail: The "Publish" request to url "https://ohpm.openharmony.cn/ohpm/feilongui" has failed
- 利用 DevEco Studio 对开发后的库模块打成 HAR 包。( 详情请见:构建 HAR)
在工具中构建 library 库时需要选中 library 文件夹内的文件
构建后所在目录为library/build/default/outputs/default/library-signed.har
后续发布需要使用这个路径
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。