鸿蒙开发环境配置搭建

最近在开发鸿蒙的应用,鸿蒙的系统底层与安卓一样都是linux底座,在linux开发的跨平台应用也可以在鸿蒙也编译,只是鸿蒙调试与编辑文件目前还不是很方便,为了记录大体过程,整理以下:

一、软件编译:

1.下载与安装DevEco Studio工具

2.在windows下使用cmake工程编译命令主要是两步:

powershell 复制代码
step1:
C:\Program` Files\Huawei\DevEco` Studio\sdk\default\openharmony\native\build-tools\cmake\bin\cmake -G "Ninja" -D OHOS_STL=c++_shared -D OHOS_ARCH=arm64-v8a -D OHOS_PLATFORM=OHOS  -DCMAKE_MAKE_PROGRAM=ninja -D CMAKE_TOOLCHAIN_FILE=C:\Program` Files\Huawei\DevEco` Studio\sdk\default\openharmony\native\build\cmake\ohos.toolchain.cmake ..
step2:
C:\Program` Files\Huawei\DevEco` Studio\sdk\default\openharmony\native\build-tools\cmake\bin\cmake --build .

hdc命令使用,感谢csdn网友的提供

https://blog.csdn.net/Androidbye/article/details/147536927

二、连接设备(使用usb线连接设备)

1.hdc list targets (获取设备信息)

2.hdc shell (进入板的命令行终端)

二、连接设备(使用网络连接设备)

1.hdc tmode port 6666 (设置使用网络方式连接设备, hdc tmode usb为使用usb连接方式)

2.hdc tconn 192.168.151.216:6666

3.hdc shell (进入板的命令行终端)

三、同时启用 hdc tcp 和 usb 模式

#进入shell终端

hdc shell

#设置属性 persist.hdc.mode 为all ,同时启用hdc tcp和usb模式

param set persist.hdc.mode all

#设置属性 persist.hdc.port 端口号

param set persist.hdc.port 6666

#设置属性 persist.hdc.mode 为tcp ,启用hdc tcp模式

param set persist.hdc.mode tcp

#设置属性 persist.hdc.mode 为usb ,启用hdc usb模式

param set persist.hdc.mode usb

四、设置静态ip

powershell 复制代码
#本地创建一个新的配置文件
cat > ethernet_interfaces.json <<EOF
{
  "config_ethernet_interfaces":[
    {
      "iface":"eth0",
      "caps":[
      ],
      "ip":"192.168.0.10",
      "gateway":"192.168.0.1",
      "dns":"",
      "netmask":"255.255.255.0",
      "route":"0.0.0.0",
      "routemask":"0.0.0.0"
    }
  ]
}
EOF

#修改system分区为可写并上传配置文件

powershell 复制代码
hdc shell "mount -o rw,remount /"
hdc file send ethernet_interfaces.json /system/etc/communication/netmanager_ext/

#重启生效

hdc shell reboot

#重启后确认生效

hdc shell "ifconfig eth0"

五、文件传输(支持整个目录传输)

1.发送文件 hdc file send .\a.txt /data/local/tmp/

2.接收文件 hdc file recv /data/local/tmp/a.txt ./

六、安装包

1.安装包 hdc install test.hap

2.卸载包 hdc uninstall test.hap

七、增加shell脚本自动启动

1.hdc_std shell mount -o remount,rw /

hdc_std shell mount -o remount,rw /system

hdc_std shell mount -o remount,rw /vendor

2.创建 init 配置文件 (.cfg)

init 配置文件是告诉系统在启动时做什么的蓝图。你需要为你的脚本创建一个专属的 .cfg 文件。

文件名:你可以取一个有意义的名字,比如 my_script.cfg。

文件内容:按照下面的模板进行配置。把文件推到/vendor/etc下面json

powershell 复制代码
{
    "jobs" : [{
        "name" : "boot",
        "cmds" : [
            "start my_service"
        ]
    }],
    "services" : [{
        "name" : "my_service",
        "path" : ["/data/local/my_script.sh"],
        "uid" : "root",
        "gid" : ["root", "shell"],
        "oneshot" : true
    }]
}
相关推荐
程序猿追1 小时前
HarmonyOS 7 WebSocket 实时消息,断开重连后怎样只显示一条回信
websocket·华为·harmonyos
OH_TPC4 小时前
@ohos/grpc 源码解读(三):连接池化与并发——三级锁、写工作线程与 JS 排干释放
harmonyos
时光慢煮4 小时前
鸿蒙 PC 上用 Electron 跨平台框架做窗口焦点:景深台 DepthDeck 的景深光学模型与 HAP 上屏实战
华为·electron·harmonyos
时光慢煮4 小时前
鸿蒙 PC 上用 Electron 跨平台框架俯瞰窗口:窗寰 Panoria 的三维投影、编队回放与 HAP 上屏实战
华为·electron·harmonyos
程序猿追5 小时前
用 HarmonyOS 7 AppStorage 处理交接台的试排与共享阶段
harmonyos
NJPJI_Yang7 小时前
鸿蒙操作系统使用 ArkTS 状态管理 V2 实现跨页面共享与持久化实战(本文已在AtomGit仓库开源)
华为·开源·harmonyos
渣哥搞AI8 小时前
在鸿蒙 PC 上用 Electron 写鸿蒙 PC 应用:星枢 AstroHub 的跨平台框架落地与 16 路能力调用拓扑
华为·harmonyos
向哆哆8 小时前
在鸿蒙PC上用ArkUI开发跨平台缓存可视化应用:CacheLoom实战
缓存·华为·harmonyos
向哆哆9 小时前
在鸿蒙PC上用Electron跨平台框架开发桌面应用:动量台 Momentum 的窗口动力学引擎与 HAP 交付实践
华为·electron·harmonyos