一、开发工具准备
下载Command Line Tools
减压到一个固定目录
放到一个不会被删掉的地方
加入环境变量
export PATH=$PATH:/Users/aaa/bbb/command-line-tools/bin
验证
命令行输入ohpm,输出以下内容就好了
二、项目准备
创建Empty Ability
File->New->Create Project
创建Library
File->New->Module
在这里插入图片描述](https://i-blog.csdnimg.cn/direct/a71fb243b7d44144aa5f46f8f57fa809.png)
三、配置oh-package.json5
{
"name": "library", // 开源库名字
"version": "1.0.0", // 版本号
"description": "Please describe the basic information.", // 描述
"main": "Index.ets", // 入口文件
"author": "mxw", // 作者,这个必填,要不发布不成功
"license": "Apache-2.0",
"dependencies": {}
}
四、生成har
选中Library,点击Build,Make Module Library,即可生成har文件,生成目录在: build->default->outputs->default
五、注册OpenHarmony三方库账号
配置公钥
在认证管理中新增公钥
公钥生成方式:
- 执行ssh-keygen -m PEM -t RSA -b 4096 -f your-keypath
- 配置私钥路径:执行ohpm config set key_path your-keypath
之后将公钥粘贴到上方,标题自己定义
配置发布码
在个人中心复制发布码,在命令行执行:ohpm config set publish_id your-publishId
六、发布到三方库
执行 ohpm publish logfishing.har 发布成功后会进入人工审核,由于我使用的是测试项目,审核没通过
发布正式库时要把CHANGELOG.md,readme.md,oh-package.json5中内容写清楚,否则审核不通过
七、遇到问题
ohpm ERROR: Private key without passphrase is not supported.
这个问题的原因是生成公钥的方式不对,用这个命令重新生成
ssh-keygen -m PEM -t RSA -b 4096 -f your-keypath
ohpm ERROR: HttpCode 400 The OHPM package must contain a non-empty license file.
这个问题是需要在Library目录下增加LICENSE文件,进行开源声明。下面是一些开源库的申明文件,可以参考
Tencent is pleased to support the open source community by making Mars available.
Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
If you have downloaded a copy of the Mars binary from Tencent, please note that the Mars binary is licensed under the MIT License.
If you have downloaded a copy of the Mars source code from Tencent, please note that Mars source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms. Your integration of Mars into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within Mars.
A copy of the MIT License is included in this file.
Other dependencies and licenses:
Open Source Software Licensed under the BSD 3-Clause License:
--------------------------------------------------------------------
1. libnatpmp 20080707
Copyright (c) 2007-2008, Thomas BERNARD
All rights reserved.
The below software (2 to 4) in this distribution may have been modified by Tencent (“Tencent Modifications”). All Tencent Modifications are Copyright (C) 2016 THL A29 Limited.
2. getaddrinfo.c 1.82
Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
All rights reserved.
3. win32.cc
Copyright (c) 2004--2005, Google Inc.
All rights reserved.
4. pingCtlTable.h 1.0
Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches
All right reserved
5. google protobuf
Copyright 2014, Google Inc. All rights reserved.
Terms of the BSD 3-Clause License:
--------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of [copyright holder] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Open Source Software Licensed under the Boost Software License-Version 1.0: The below software in this distribution may have been modified by Tence