[HarmonyOS Development] The difference between Harmony Control and native App

The difference between controls and applications should be a topic rarely mentioned. When I first entered Hongmeng Circle, I was exposed to the development of high-end controls, which triggered a lot of thinking about controls and their use, and I also stepped on a lot of questions. Damn it, record it.

1. What are Hongmeng advanced controls?

Hongmeng Control is an SO that needs to be written into the mobile phone system. Our control has only one JS file, through BUILD.gn and xxx.cppCompile the filexxx.js into SO. Finally, burn the SO package into the Hongmeng system through the hdc tool command.

1.1 hdc common commands

// 查看设备是否连接
hdc list targets

// 以读写模式挂载系统分区
hdc shell mount -o rw,remount /

// 将本地文件,加载到系统的/system/lib64/module/arkui/advanced/
这个位置
hdc file send libtesthelloworld.z.so /system/lib64/module/arkui/advanced/

// 同步so到系统
hdc shell sync

// 重启设备
hdc shell reboot

 1.2 SO compilation command

// 将开发包的控件代码放入华为计算云指定位置
/home/user/code/oh_code/foundation/arkui/ace_engine/advanced_ui_component

// 配置编译环境(仅第一次执行)
./build/prebuilts_download.sh --tool-repo=http://hmf.inXXXXX.com:9080 --npm -registry=http://mirrors.tools.XXXXX.com/npm/ --trusted-host=mirrors.tools.XXXXX.com --pypi-url=http://mirrors.tools.XXXXX.com/pypi/simple-skip-ssl

// 编译SO
./build_system.sh --abi-type generic_generic_arm_64only --device-type hisi_all_phone_standard --ccache --build-variant root --build-target ace_engine

// 获取我们编译出来的SO包
/home/user/code/oh_code/out/generic_generic_arm_64only/hisi_all_phone_standard/arkui/ace_engine

2. The difference between components and applications

        App application: You can call any resources in the package. We can also introduce Chinese and English through resources, which is highly customizable.

        High-order controls: Applications written into the Hongmeng system can only rely on the capabilities existing in the system for secondary development, or develop underlying applications through C++ and provide them to ArkTS for calling.

  • The control can only call system resources ($r(sys.xx.xx)). If you need to use resources such as images, you need to convert them to base64 format for import;
  • Hongmeng’s Icon icon resources in API 9 have not yet been introduced into the Hongmeng system, and only some of them have been introduced in API 11;
  • There is a problem with the Chinese and English components. The control needs to call the system language package, and the one written in resources will not work;
  • As a control, in principle, it does not do any business logic processing, and only does two things, obtaining input parameter function processing, throwing callbacks/values, etc.;
  • Do not call some methods of the application layer, such as router, etc. in the control layer, otherwise it will cause problems such as SO crash;

3. Problem record (continuously updated)

3.1 Drag event conflict (GridItem can be dragged, but the wrapped Image cannot be dragged)

Reason:Drag event conflict

Solution:Image adds draggable attribute and sets it to false

Reflection:Hongmeng’s API documentation is not very reliable (encountered it many times), The API properties of each version are not necessarily the same by default, and some properties need to be tested by yourself.

Image("sys.media.ic_public_ok").draggable(fasle)

2023/12/05 12:10

Not finished, waiting for further updates...

Guess you like

Origin blog.csdn.net/qq_23334071/article/details/134764626