Open up hongmeng, who is the love, are only strong romantic feelings

The first time I knew the word “hongmeng” was at the beginning of a Dream of Red Mansions. Hongmeng, in classical culture, refers to the chaotic state before the formation of the universe, which means before the creation of the universe.

For mobile developers, React Native and Flutter have been joined by a mobile development platform and framework called Hongmeng OS application development. As a former mobile developer, I decided to try something new.

The development environment

Hongmeng OS application development IDE for DevEco Studio, and Android Studio are based on Jetbrain IntelliJ IDE community open source version, so the interface almost looks the same

Unlike Android, Java and Javascript are provided as two development languages. This article will only introduce the way through Java. Since Hongmeng development is very similar to Android, we will compare the two mobile platforms.

Download address: developer.harmonyos.com/cn/develop/…

As of this writing, DevEco Studio is Windows only, and Windows virtual machines are only available on Macs.

  • Once you download it, you install the SDK, and at this point you don’t need to go to the Internet to download it, much better than Android

  • Project code generated using scaffolding

Application construction:

  • Tools: Gradle, same as Android, but Android is pushing bazel builds

The virtual machine

At present, it seems that Hongmeng does not provide local virtual machines. If you want to debug and run the application, you need to register a Huawei development account, and you can add a “remote machine” in the VIRTUAL machine management Settings.

File structure

  • entryThe directory is the default Module directory, similar to Androidappdirectory
  • entry/src/main/javaIs the function code,src/testThe test code is the same as Android
  • entry/src/main/resourceResource directory with Androidsrc/main/ressimilar
  • entry/src/main/config.jsonConfigure the code or entry configuration for the project, similar to an Android manifest fileAndroidManifest.xml, describes the package name, requested system permissions, entry pages, and so on

Some of the concepts

  • Ability: Similar to Android activity, so the default Ability is also called MainAbility; Translated into Chinese called “ability”, I said very confused, puzzled
  • AbilitySlice: Kind of like AndroidFragmentTo complete the binding layout
  • AbilityPackage: Application class similar to Android
  • HVD: Hongmeng VIRTUAL machine, similar to Android AVD
  • HAP: Hongmeng application installation package extension, similar to Android.apk

Code sample

  • MainAbility (Activity)
package cn.wangbaiyuan.blog;

import cn.wangbaiyuan.blog.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;

public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(MainAbilitySlice.class.getName()); }}Copy the code
  • AbilitySlice (Fragment)
package cn.wangbaiyuan.blog.slice;

import cn.wangbaiyuan.blog.data.ListHolder;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

public class MainAbilitySlice extends AbilitySlice {
    private ListHolder listHolder;

    @Override
    public void onStart(Intent intent) {
        listHolder = new ListHolder(this);
        setUIContent(listHolder.createComponent());
    }

    @Override
    public void onActive(a) {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent); }}Copy the code
  • Layout code to achieve a left and right layout:

      
<DirectionalLayout
   xmlns:ohos="http://schemas.huawei.com/res/ohos"
   ohos:width="match_parent"
   ohos:height="56vp"
   ohos:orientation="horizontal">
 <Text
    ohos:id="$+id:left_content"
    ohos:width="match_content"
    ohos:height="match_content"
    ohos:weight="1"
    ohos:text_alignment="center"
    ohos:text_size="16fp"
    ohos:text="left"
 />

 <Text
    ohos:id="$+id:right_content"
    ohos:width="match_content"
    ohos:height="match_content"
    ohos:weight="1"
    ohos:text_alignment="center"
    ohos:text_size="16fp"
    ohos:text="right"
 />
</DirectionalLayout>
Copy the code

conclusion

According to the above, there is almost no learning cost for an Android developer to learn. While there is a lot of Android in there, we can’t assume it’s Android, just that it borroves from Android in terms of API design and gives mobile developers a friendly feel.

As a Chinese, I hope China’s software development can continue to rise, and the underlying technology and framework, open source atmosphere can be in line with Europe and the United States.