体验Windows本地编译OpenHarmony 2.0 Canary 精华

obarong
发布于 2021-6-27 08:56
浏览
5收藏

之前用Ubuntu虚拟机来编译鸿蒙源码,听说DevEco Device Tool 2.2 Beta1可以在Windows一站式编译。马上尝尝。

1 准备工作

参考社区的文档

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

参考官网文档,部署Windows环境

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

上官网下载HUAWEI DevEco Device Tool 2.2 Beta1,简称DDT,关闭VScode后直接安装。

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

检查各种工具的版本,我的VS code要升级一下,打开即会自动更新,更新完重启VS code即可。其他工具的更新也是参考官方文档就行,文档很全。

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

官网的文档说支持Linux编译,我有点懵圈。

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

看这个文档才对

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

下载好源码,用bandizip解压一堆报错,换成在PowerShell用tar解压

tar -zxvf code-2.0-canary.tar.gz

这是全量代码,解压花了十多分钟。

安装MinGW勾选这2个。其实只勾最下边那个就可以了吧?

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

在VScode设置工具链

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

2 编译

打开源码

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

编译成功。

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

花了90s,想要加快速度最好用服务器编译。

3 烧录

修改applications\sample\wifi-iot\app\BUILD.gn

lite_component("app") {
    features = [
        #"startup",
        "iothardware:led_example"
    ]
}

编译Led demo

参考官网,设置端口

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

烧录成功

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

4 一些报错

  • 打开工程报错
[2021/6/26下午5:46:22] 无法使用 compilerPath“riscv32-unknown-elf-gcc”解析配置。 请改用“D:\tool\Strawberry\c\bin\gcc.exe”。
无法找到“D:\HarmonyDev\code-2.0-canary\include”。
无法找到“D:\HarmonyDev\code-2.0-canary\src”。
无法找到“riscv32-unknown-elf-gcc”。

不用管

  • 编译报错
[OHOS ERROR] [151/303] COPY ../../../foundation/distributedschedule/samgr_lite/config/system_capability.json obj/foundation/distributedschedule/samgr_lite/config/system_capability.json
[OHOS ERROR] FAILED: obj/foundation/distributedschedule/samgr_lite/config/system_capability.json
[OHOS ERROR] python D:/HarmonyDev/code-2.0-canary//build/lite/copy_files.py --src_type=file --src=../../../foundation/distributedschedule/samgr_lite/config/system_capability.json --dest_dir=obj/foundation/distributedschedule/samgr_lite/config/system_capability.json
[OHOS ERROR] Fatal Python error: init_sys_streams: can't initialize sys standard streams
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR]   File "C:\Users\qweto\AppData\Local\Programs\Python\Python38\lib\io.py", line 54, in <module>
[OHOS ERROR] ImportError: cannot import name 'open_code' from 'io' (unknown location)

解:
按照网友的方法:

1.卸载DevEco Device Tool,卸载VS Code,卸载Python

2.删除C:\Users\Administrator.deveco-device-tool\core文件夹

3.安装Python,VS Code,DevEco Device Tool 2.2 Beta1

  • 重新安装DDT报错,找不到python3

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

查看日志"C:\Users\qweto\AppData\Local\deveco-device-tool-installer\deveco-install.log"

Looking for python3 
looking in registry bunch "HKEY_CURRENT_USER\Software\Python\PythonCore" 
check path D:\Program Files (x86)\Python38-32\python.exe 
check path 1 匹配。 
looking in registry bunch "HKEY_LOCAL_MACHINE\Software\Python\PythonCore" 
Python3 is not found. Aborted. 

指向一个以前安装过的python版本,卸载不干净。删掉注册表的3.8-32,不行。

体验Windows本地编译OpenHarmony 2.0 Canary-鸿蒙开发者社区

解:
下载官方文档推荐的版本,单独安装Python,不要用anaconda的,那个识别不到。

  • 卸载Python3.8,保留了Anaconda用的3.7.4版本,但是DDT的主页直接打不开了。

尝试更新一下conda

conda update --all

还是一样。Anaconda更新后打不开了,卸载重装。

conda报错

Collecting package metadata (current_repodata.json): failed
check_hostname requires server_hostname

解:删除.condarc无效,退出代理软件有效。

DDT只认单独安装的Python,不认conda的。

参考

DevEco Device Tool 2.2 Beta1 在Windows环境一站式编译烧录体验-鸿蒙HarmonyOS技术社区-鸿蒙官方战略合作伙伴-51CTO.COM
https://harmonyos.51cto.com/posts/5821

IDE - HarmonyOS设备开发官网
https://device.harmonyos.com/cn/ide#download_release

用户指南-Windows开发环境准备
https://device.harmonyos.com/cn/docs/ide/user-guides/install_windows-0000001050164976

zh-cn/device-dev/quick-start/Readme-CN.md · OpenHarmony/docs - Gitee
https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Readme-CN.md

用户指南-Windows平台源码编译
https://device.harmonyos.com/cn/docs/ide/user-guides/hi3861_windows-0000001101110444

(完)

8
收藏 5
回复
举报
14条回复
按时间正序
/
按时间倒序
longlong899
longlong899

不错 !!学习了!

回复
2021-6-28 10:14:55
鸿联
鸿联

  3516,3518开发板仅支持Linux下编译,3861支持Windows和Linux下编译。

1
回复
2021-6-28 15:17:01
obarong
obarong

看串口日志才发现,系统在不停重启。原因不明。报错日志

Start to run test suite:CmsisTaskFuncTestSuite
Run test suite 1 times
../../../test/xts/acts/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c:396:testOsThreadNew001:PASS
../../../test/xts/acts/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c:67:testOsThreadNew002:FAIL: Expected 3 Was 2
../../../test/xts/acts/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c:479:testOsThreadNew003:FAIL: Expected Non-NULL
../../../test/xts/acts/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c:124:testOsThreadNew004:FAIL: Expected Non-NULL
runned:0, tickB:783, tickA:783, loop:10000
……
Start to run test suite:DBMKvStoreFuncTestSuite
Run test suite 1 times
+-begin----------------------------------------+
../../../test/xts/acts/distributeddatamgr_lite/dbm_kv_store_hal/src/dbm_kv_store_func_test.c:47::FAIL: Expected 0 Was -1GetKVStore: begin[1827] finish[1827] use[0]
=======KERNEL PANIC=======

**********syserr info start**********
kernel_ver      : Hi3861V100 R001C00SPC025,2020-09-03 18:10:00
……

 

回复
2021-7-10 22:48:46
远道可思
远道可思 回复了 obarong
看串口日志才发现,系统在不停重启。原因不明。报错日志 Start to run test suite:CmsisTaskFuncTestSuite Run test suite 1 times ../../../test/xts/acts/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c:396:testOsThreadNew001:PASS ../../../test/xts/acts/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c:67:testOsThreadNew002:FAIL: Expected 3 Was 2 ../../../test/xts/acts/kerne...

那个是测试用例,可以将test/xts/acts/build_lite/BUILD.gn中ohos_kernel_type == "liteos_m"中全部屏蔽

回复
2021-7-10 22:57:40
liangkz_梁开祝
liangkz_梁开祝 回复了 obarong
看串口日志才发现,系统在不停重启。原因不明。报错日志 Start to run test suite:CmsisTaskFuncTestSuite Run test suite 1 times ../../../test/xts/acts/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c:396:testOsThreadNew001:PASS ../../../test/xts/acts/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c:67:testOsThreadNew002:FAIL: Expected 3 Was 2 ../../../test/xts/acts/kerne...

看来你编译的是debug版本,可以加“-b release”参数编译发布版本,就不会跑测试用例了。

可以去 out\hispark_pegasus\wifiiot_hispark_pegasus\args.gn 文件查看 ohos_build_type 是 "release" 还是“debug”进行确认。

已于2021-7-11 06:36:02修改
2
回复
2021-7-11 06:34:39
姚太龙
姚太龙
  1. 🤙🤙🤙 
回复
2021-7-11 10:00:38
鸿联
鸿联

源码默认build—type为“debug”。第一次打开工程未编译之前,需修改build—type为“release”

经试验,如果编译之后再修改,修改参数就不会起作用了,可能是源码的一个bug

回复
2021-7-11 11:08:57
obarong
obarong 回复了 远道可思
那个是测试用例,可以将test/xts/acts/build_lite/BUILD.gn中ohos_kernel_type == "liteos_m"中全部屏蔽

应急有用

回复
2021-7-17 23:37:11
obarong
obarong 回复了 liangkz_梁开祝
看来你编译的是debug版本,可以加“-b release”参数编译发布版本,就不会跑测试用例了。 可以去 out\hispark_pegasus\wifiiot_hispark_pegasus\args.gn 文件查看 ohos_build_type 是 "release" 还是“debug”进行确认。

out\hispark_pegasus\wifiiot_hispark_pegasus\args.gn最后一次修改在创建工程时,现在改工程设置不会影响这个文件。ohos_build_type 确实是“debug“,手动改成”release“,重新编译就行了。但是这样还是没能解决debug的测试用例Fail问题。

回复
2021-7-17 23:41:23
拓维信息Abin
拓维信息Abin

我搭建环境编译出现这种错误,怎么解

[OHOS INFO] [205/208] STAMP obj/test/xts/acts/build_lite/acts.stamp
[OHOS INFO] [206/208] STAMP obj/build/lite/ohos.stamp
[OHOS INFO] [207/208] ACTION //device/hisilicon/hispark_pegasus/sdk_liteos:run_wifiiot_scons(//build/lite/toolchain:riscv32-unknown-elf)
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR]   File "c:\users\aibin\.deveco-device-tool\core\deveco-venv\lib\site-packages\hb\__main__.py", line 80, in main
[OHOS ERROR]     status = args.command(args)
[OHOS ERROR]   File "c:\users\aibin\.deveco-device-tool\core\deveco-venv\lib\site-packages\hb\build\build.py", line 94, in exec_command   
[OHOS ERROR]     return build.build(args.full, cmd_args=cmd_args)
[OHOS ERROR]   File "c:\users\aibin\.deveco-device-tool\core\deveco-venv\lib\site-packages\hb\build\build_process.py", line 119, in build 
[OHOS ERROR]     exec_cmd(cmd_args)
[OHOS ERROR]   File "c:\users\aibin\.deveco-device-tool\core\deveco-venv\lib\site-packages\hb\build\build_process.py", line 200, in ninja_build
[OHOS ERROR]     exec_command(ninja_cmd, log_path=self.config.log_path, log_filter=True)
[OHOS ERROR]   File "c:\users\aibin\.deveco-device-tool\core\deveco-venv\lib\site-packages\hb\common\utils.py", line 99, in exec_command  
[OHOS ERROR]     for line in iter(process.stdout.readline, ''):
[OHOS ERROR]   File "D:\Program Files\Python38\lib\codecs.py", line 322, in decode
[OHOS ERROR]     (result, consumed) = self._buffer_decode(data, self.errors, final)
[OHOS ERROR] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 1172: invalid continuation byte
[OHOS ERROR] Unhandled error: 'utf-8' codec can't decode byte 0xd5 in position 1172: invalid continuation byte
*** [out\hispark_pegasus\wifiiot_hispark_pegasus\Hi3861_wifiiot_app.out] Error -1
====================================================== [FAILED] Took 16.09 seconds ======================================================
终端进程“c:\users\aibin\.deveco-device-tool\core\deveco-venv\scripts\hos.exe 'run', '--project-dir', 'H:\harmony-canary', '--environment', 'hi3861'”已终止,退出代码: 1。
已于2021-7-23 15:35:20修改
1
回复
2021-7-23 15:33:52
txwtech
txwtech

博主好,请问这个版本,hi3861 gpio上拉如何操作呢?

canary没有这个功能呢

IoSetPull(WIFI_IOT_IO_NAME_GPIO_8, WIFI_IOT_IO_PULL_UP);

回复
2021-8-19 09:29:22
Hello_Kun
Hello_Kun 回复了 拓维信息Abin
我搭建环境编译出现这种错误,怎么解 [OHOS INFO] [205/208] STAMP obj/test/xts/acts/build_lite/acts.stamp [OHOS INFO] [206/208] STAMP obj/build/lite/ohos.stamp [OHOS INFO] [207/208] ACTION //device/hisilicon/hispark_pegasus/sdk_liteos:run_wifiiot_scons(//build/lite/toolchain:riscv32-unknown-elf) [OHOS ERROR] Traceback (most recent call last): [OHOS ERROR] File "c:\use...

我的也是utf-8报错,您解决了么

回复
2021-8-22 11:26:31
拓维信息Abin
拓维信息Abin 回复了 Hello_Kun
我的也是utf-8报错,您解决了么

我的解决了,原因是out目录下面的build.log文件有问题,再加上代码编译出错,从build.log文件中读取错误日志信息时出错了。不知为啥clean命令无法清除掉build.log文件,所以这个文件一旦异常了,就一直存在,就一直出现出现utf-8问题。

 

解决方案是  直接手动删除build.log文件,或者手动删除整个out目录,

1
回复
2021-8-23 09:39:07
Hello_Kun
Hello_Kun

嗯嗯。我的也解决了,是因为我之前的一个系统盘被我删除了,我建了一个空的盘,欺骗一下就通过了。

回复
2021-8-25 21:55:06
回复
    相关推荐