table of Contents
On June 2, 2021, the Hongmeng system ushered in the second open source. At the same time, the DevEco Studio used to develop the Hongmeng App also ushered in a major update. This update is a milestone because it adds a lot of The function of Niu Cha, and the compilation speed has been significantly improved. Especially for distributed simulators, distributed Hongmeng App can be developed without a real machine. This article will explain in depth some of the core features introduced by DevEco Studio.
1. Distributed remote simulator
The distributed remote simulator is the most worthwhile feature in the new version of DevEco Studio. The previous remote simulator can only test stand-alone and network applications, but Hongmeng's distributed features can only be tested with real machines. The distributed remote simulator allows two remote simulators (P40+P40 or P40+MatePad Pro) to be created at the same time. The two remote simulators can access each other, and the device ID of the other can be obtained by using the related distributed API, so Can be used to develop distributed Hongmeng App.
By default, the distributed remote simulator is not turned on. To enable this function, enter the IDE's settings window, click DevEco Labs in the tree on the left, and select the Enable Super Device check box on the right, as shown in the figure below.
Then click the Tools> Device Manager menu item, and the HarmonyOS Virtual Device Manager window will open (you need to log in to the Huawei developer website first), as shown in the figure below.
A Super device node will appear at the bottom, and there are two combinations: P40+P40 and P40+MatePad Pro. Just select one combination.
After it is done, two simulators will appear on the right side of the IDE main window, as shown in the figure below. Their port numbers are 18888 and 18889 respectively.
Execute the hdc list targets command, the following two devices will be displayed:
127.0.0.1:18888 device 127.0.0.1:18889 device
If you think the emulator window is too small, you can directly use scrcpy to remotely project the screen. The command line is as follows:
scrcpy -s 127.0.0.1:18888
The effect after projection is shown in the figure below, so that you can have a remote simulator with a separate window.
Now you can run a distributed app. For example, the following app can obtain other devices in the network. Currently, only one device is obtained, which is the other of the dual simulators.
2. Local emulator
Although the remote emulator is very useful and takes up less resources, it has the following two disadvantages:
(1) The remote simulator must be connected to the Internet, which is not friendly to users who do not have a network environment or have a bad network environment;
(2) Due to the difference of the network, the remote simulator may be slow to respond and the user experience is not good;
Based on the above two shortcomings, the latest version of DevEco Studio has also launched a local emulator, that is, installing HarmonyOS in a local virtual environment, which greatly improves operating efficiency.
If you want to use the local emulator, you can turn on the Enable Local Emulator option in DevEco Labs, as shown in the figure below.
Then you will see the Local Emulator tab in the device management, as shown in the figure below. However, the mirrors of the local emulator have not been released yet. Huawei will release these mirrors later, and users can click the Install button to download them. When the local emulator is released, I will write an article to explain it in detail.
3. Changed the way of creating projects
The new version of the IDE has changed the way to create a project, first of all, it is required to select a template, as shown in the figure below.
Eleven cross-device templates have been added to this template, as shown below.
In the next step, you will be asked to select the device to which the template applies, as shown in the figure below. Depending on the selected template, all optional devices applicable to the template will appear below, if not applicable, it will not be displayed.
4. Atomization Service
Most of the above windows are some conventional settings. Here to mention Project Type. There are two options: Service and Application. Among them, Application is an ordinary App, so there is no need to introduce it. The Service is an atomic service App. After the Service App is installed, there is no icon on the desktop. And the size of the app must be limited to less than 10MB. Upload to the Huawei App Market will automatically download and install it from the Huawei App Market through certain conditions (such as cross-device transfer) (the user is completely unaware of it).
And creating an atomic service will automatically create a card, as shown in the figure below.
If the last Show in Service Center check box is checked, it will be displayed in Hongmeng's service center.
Enter the service center by swiping from the bottom left corner of the phone screen to the top right.
Now modify the string.json file according to the following style.
Next, run it on the emulator or mobile phone, then enter the service center, enter FirstAtomApp, and you will see this program, as shown in the figure below. In fact, this is the card in the App.
Then click and the Ability associated with it will pop up, as shown in the figure below. However, the Service type App does not have an icon, so it can only be started from the service center search, or can be started only when certain conditions are met, such as data flow, NFC, etc.
5. A good helper for learning: Samples
Hongmeng has a CodeLabs (see the following page), but the examples inside are a bit big, so the IDE provides a lot of samples (relatively small).
There are two ways to import samples.
Method 1. On the welcome interface (as shown in the figure below), click Import HarmonyOS Sample.
Then the following window will pop up, select one of them, click the Next button, and follow the prompts to import a specific Sample.
Method 2: In the IDE, click File> New> Import HarmonyOS Sample menu item, and the Import HarmonyOS Sample window will pop up.
In fact, Samples does not open the project directly, but pulls it from gitee (code cloud). These cases can also be obtained from the following page.
6. Application self-signed
We know that HarmonyOS App needs to be signed when deployed on a real machine. In the past, it was necessary to go to AppGallery Connect to generate some configuration files for signing, and then enter the Project Structure window to complete the configuration as shown in the figure below.
In the new version of the IDE, an Automatically generate signing check box is provided. Select the check box and create an application with the same package name as the current project on AppGallery Connect, and the relevant signature file can be automatically generated. The effect is as shown in the figure below. Shown.
However, the following two points should be paid attention to when using automatic signature:
(1) There must be a Hongmeng device connected to the PC (either via USB or remote connection)
(2) All devices connected to the PC must be Hongmeng devices, and no Android devices. Of course, Apple devices are fine
If an Android device is connected to the PC at the same time, the following exception will be thrown during auto-signing:
The reason for the error is that the system will sign all physical devices. At present, it is not judged whether it is a Hongmeng device or an Android device. So if you encounter an Android device, you will also sign it. Of course, Android devices cannot successfully sign the HarmonyOS App, so the signature will fail (as long as one device fails to sign, all devices will fail to sign).
Of course, the new version of the IDE has many other functions. I will write an article to introduce them later, so stay tuned!