最近在开发鸿蒙的应用,鸿蒙的系统底层与安卓一样都是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
}]
}