DEV Community

wei chang
wei chang

Posted on

How to run and debug projects when developing HarmonyOS applications with Uniapp

After a few days of sharing, everyone should have a certain understanding of the development syntax for using uniapp to develop HarmonyOS applications and be able to carry out some simple application development. Today, I will share how to run HarmonyOS devices when using uniapp to develop HarmonyOS applications and how to debug programs during the development process.
Run
The Uniapp project supports running on HarmonyOS real devices and emulators. However, before that, you must first create an application on the AppGallery Connect official website and copy the package name.
The second step is that if you want to run it on the real device, just connect your mobile phone directly to the computer. If you want to run to the simulator, open DevEco, open any project at random, and start the simulator.
Then, under the run menu of HbuilderX, select "Run to HarmonyOS". If it's your first time running, you may need to download the real machine run plugin here

Image description

Then you will see a list of devices. At this point, select the configuration certificate at the bottom, fill in the package name of the application you just created in a new pop-up window, and then click "Automatically Apply for Debug Certificate". After the information is automatically filled in, save it.

Image description

Select the run project again. At this point, the project will successfully run on the corresponding device
Print log
In the uniapp project, the console.log method is mainly used to print logs. The printed logs will directly appear in the console below. The logs not only contain the content but also the corresponding page path and even which line it is on.

Image description

You can also check the "Show Native Logs" option on the right, and you will see more accurate running information.
Breakpoint debugging
Breakpoints can also be set directly in the project code in the Uniapp project. However, it is currently only supported in the uni-app x project, and the HbulderX version needs to be above 4.61.

Image description

Open HbulderX, create the uni-app x project, and click the red spider button in the upper right corner of the console to open debugging

Image description

Now, double-click on the left side of the code where you want to interrupt to bring up the breakpoint identifier. Then the program will stop when it reaches this point.

Image description

On the spider bar on the left, all the breakpoint information can be seen, and breakpoints can be managed uniformly here.

Image description

The above is all the relevant content about running the uniapp project to HarmonyOS and debugging. Thank you for reading.

Top comments (0)