add OpenHarmony JS项目开发流程.md

This commit is contained in:
ShengyaoWu 2021-07-23 09:35:22 +08:00
parent fba7e00314
commit 2739550208
26 changed files with 141 additions and 0 deletions

View File

@ -0,0 +1,141 @@
## 一、配置OpenHarmony开发环境
### 1.1软件需求
1下载并安装好DevEco Studio 2.1 Release及以上版本下载链接https://developer.harmonyos.com/cn/develop/deveco-studio#download
2获取OpenHarmony SDK包并解压下载链接https://developer.harmonyos.com/cn/develop/deveco-studio#download
### 1.2配置OpenHarmony SDK
在DevEco主界面点击工具栏中的File> Settings > Appearance & Behavior > System Settings > HarmonyOS SDK界面点击HarmonyOS SDK Location加载SDK如图1.2.1、1.2.2、1.2.3、1.2.4所示:
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image002.jpg)
<center>图1.2.1</center>
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image004.jpg)
<center>图1.2.2</center>
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image006.jpg)
<center>图1.2.3</center>
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image008.jpg)
<center>图1.2.4</center>
之后一路Next、Finish完成配置。
### 1.3安装额外包
进入**OpenHarmony-SDK-2.0-Canary\js\2.2.0.0\build-tools\ace-loader**目录然后在该目录下运行命令行工具分别执行如下命令直至安装完成如图1.3.1所示:
```
npm cache clean -f
npm install
```
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image010.png)
<center>图1.3.1</center>
至此OpenHarmony 开发环境配置完成。
## 二、创建、打开OpenHarmony JS工程
### 2.1 使用DevEco2.1 Release版本
2.1版本的DevEco针对OpenHarmony应用开发只能通过导入Sample工程的方式来创建一个新工程目前支持OpenHarmony应用开发的Sample工程请选择导入含有**“This sample is intended for novices at developing OpenHarmony applications.”**说明的Sample例如选择common分类中的JsHelloWorld。如图2.1.1、2.1.2所示:
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image012.jpg)
<center>图2.1.1</center>
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image014.jpg)
<center>图2.1.2
Sample导入后请打开工程下的build.gradle修改hap插件的版本号为**“2.4.4.3-RC”**如图2.1.3所示:
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image016.jpg)
<center>图2.1.3
最后执行gradle sync等待同步完成。同步成功后便可以进行OpenHarmony应用开发了。
### 2.2 使用DevEco2.2 beta版本
2.2版本的DevEco可以在菜单栏选择**File > New > New Project**来创建一个OpenHarmony工程与HarmonyOS工程的创建方法一致。
## 三、配置签名证书,编译
在完成应用开发后需要打包为Hap才能够安装带OpenHarmony开发板中。并且没有配置证书的Hap无法被安装到OpenHarmony开发板中所以在在打包Hap前首先需要配置证书。
### 3.1 申请证书
OpenHarmony与HarmonyOS的证书不通用所以需要额外进行申请具体申请流程可以参考[https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/%E9%85%8D%E7%BD%AEOpenHarmony%E5%BA%94%E7%94%A8%E7%AD%BE%E5%90%8D%E4%BF%A1%E6%81%AF.md](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/配置OpenHarmony应用签名信息.md)
### 3.2 配置证书
OpenHarmony与HarmonyOS的证书的配置方法相同同样可以参考: [https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/%E9%85%8D%E7%BD%AEOpenHarmony%E5%BA%94%E7%94%A8%E7%AD%BE%E5%90%8D%E4%BF%A1%E6%81%AF.md](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/配置OpenHarmony应用签名信息.md)
### 3.3 编译
OpenHarmony与HarmonyOS的应用的打包方法相同。在工具栏点击**Build->Build Hap(s)/APP(s)->Build Hap(s)**如图3.3.1所示:
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image018.jpg)
<center>图3.3.1
等待项目编译完成图3.3.2为编译成功的显示:
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image020.jpg)
<center>图3.3.2
在工程文件的build目录下找到**XXXXXX-signed.hap**这个就是可以在开发板中安装的Hap包如图3.3.3所示。
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image022.jpg)
<center>图3.3.3
## 四、推送到开发板/设备
### 4.1下载hdc_std工具
与HarmonyOS设备使用的hdc工具不同OpenHarmony需要hdc_std作为调试工具hdc-std下载链接https://gitee.com/openharmony/developtools_hdc_standard
### 4.2 配置环境变量Windows
将**hdc_std.exe**添加到系统的环境变量中。在cmd中输入**”hdc_std -h”**验证环境变量是否添加成功。
### 4.2 使用hdc_std安装Hap
使用usb连接开发板后使用**”hdc_std install <file_path>”**来安装在3.3节中编译好的Hap如图4.2.1所示:
![img](file:///C:/Users/WUSHEN~1/AppData/Local/Temp/msohtmlclip1/01/clip_image024.jpg)
<center>图4.2.1
## 五、运行
以Hi3516DV300开发板为例在开发板屏幕上点击应用图标即可打开应用。

BIN
figs/clip_image001.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
figs/clip_image002.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
figs/clip_image003.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

BIN
figs/clip_image004.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
figs/clip_image005.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

BIN
figs/clip_image006.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
figs/clip_image007.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

BIN
figs/clip_image008.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
figs/clip_image009.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
figs/clip_image010.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

BIN
figs/clip_image011.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

BIN
figs/clip_image012.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
figs/clip_image013.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
figs/clip_image014.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
figs/clip_image015.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
figs/clip_image016.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
figs/clip_image017.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
figs/clip_image018.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
figs/clip_image019.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

BIN
figs/clip_image020.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
figs/clip_image021.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
figs/clip_image022.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
figs/clip_image023.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
figs/clip_image024.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB