SoFunction
Updated on 2025-03-04

Hongmeng Development builds a flutter-compatible development environment

Environment construction

1. Install DevEco Studio NEXT IDE

Note that the version should be Next, and the current latest one is Beta3. You need to log in before downloading. The simulator creation needs to be created later. The developer needs to verify, review, etc. Fortunately, the review progress is OK. After submitting the application, I passed the review for about two hours. I found the version matching my computer system to download. My computer is Window, so I chose the Window version to download. The installation steps are relatively simple, step by step until it is completed. The new version of the tool has been integrated into node and ohpm and there is no need to download and install it separately.

2. Install Git

If you want to adapt to Android at the same time, you need to install Android Studio; if you want to adapt to iOS, you need to install Xcode

Mac installation (recommended)Environment variable configuration

# Flutter Mirror
export PUB_HOSTED_URL=
export FLUTTER_STORAGE_BASE_URL=

# HarmonyOS SDK
export TOOL_HOME=/Applications//Contents/
export DEVECO_SDK_HOME=$TOOL_HOME/sdk # command-line-tools/sdk
export PATH=$TOOL_HOME/tools/ohpm/bin:$PATH # command-line-tools/ohpm/bin
export PATH=$TOOL_HOME/tools/hvigor/bin:$PATH # command-line-tools/hvigor/bin
export PATH=$TOOL_HOME/tools/node/bin:$PATH # command-line-tools/tool/node/bin

Windows InstallationConfigure user variables

FLUTTER_STORAGE_BASE_URL=
PUB_HOSTED_URL=
DEVECO_SDK_HOME=C:\Program Files\Huawei\DevEco Studio\sdk

Configure environment variablesEdit PATH, add the following path

C:\Program Files\Huawei\DevEco Studio\tools\ohpm\bin
C:\Program Files\Huawei\DevEco Studio\tools\hvigor\bin
C:\Program Files\Huawei\DevEco Studio\tools\node

Manage multiple Flutter versionsIf you need to use multiple Flutter versions in project development, you can consider using fvm 1. Install FVM 2. Use fvm official flutter version fvm install 3.22.0 3. Install a custom Hongmeng version and enter the fvm/version directory, which is usually located in the user directory, such as ~/fvm/versions/3.22.0, copy the repository and rename it to custom_x. The name git clone -b dev /openharmony-sig/flutter_flutter.git custom_3.7.12 4. Use a separate flutter sdk version in the project, and execute it in the project directory: fvm use custom_3.7.12

Create a run project

1. Detect flutter

Is it OK to create Hongmeng application conditions? Run flutter doctor -v to check whether the environment variable configuration is correct

[✓] HarmonyOS toolchain - develop for HarmonyOS devices
    • OpenHarmony Sdk at E:\ohos\DevEcoStudio\sdk, available api versions has [12:default]
    • Ohpm version 5.0.8-rc.1    #If an x ​​error is reported here, it means that the `PATH variable added value is %TOOL_HOME%\tools\ohpm\bin` has a problem with the path configuration of the environment variable ohpm added    • Node version v18.20.1      #If x error is reported here, there is a problem with the node path similar to PATH configuration    • Hvigorw binary at E:\ohos\DevEcoStudio\tools\hvigor\bin\hvigorw   #If you report herexmistake,similarPATHConfiguredhvigorThere is a problem with the path

2. Create a flutter project

Create a project Method 1 This method only creates the ohos platform flutter create --platforms ohos Enter the project root directory to compile the hap package. After creating the project, you must first perform this step to generate the dependency. If you open it directly using DevEcho Studio, you will report an error and cannot find the dependency library flutter build hap --debug

3. Run the flutter project to Hongmeng next phone

Method 1: After discovering the real device through the flutter devices command, obtain the device-id, enter the project directory to specify the construction method to compile the hap package and install it in Hongmeng mobile phone flutter run --debug -d

flutter devices
  flutter run --debug -d <deviceId>

Method 2: Enter the project root directory to compile the hap package, and then install it into the Hongmeng mobile phone

flutter build hap --debug
  hdc -t &lt;deviceId&gt; install &lt;hap file path&gt;    # similarAndroidofadbInstall:adb -s &lt;deviceId&gt; install &lt;apk file path&gt;

Method 3: Use DevEcoStudio to open the project's ohos module

  1. File --> Project Structure --> Signing Configs --> Check Automatically generate signature --> Apply, you can enable startup signature and execute the first timeflutter build hapIt will also be prompted when
  2. Create an emulator: Device Manager --> Go in and follow the prompts to plug in the emulator, but the first creation still requires developer verification and review. . .
  3. The key point is: the simulator created is only for x86 architecture, and in this article, we built the flutter application that supports Hongmeng through flutter_flutter, which only supports arm64 architecture. The document also explained, so in fact, creating an emulator is useless for flutter applications, #It must be run as a real machine

Packaging Projects

1. Package the test package

flutter build hap --debug

If you need to specify the engine, use the --local-engine parameter to use flutter build hap --debug --local-engine=E:\ohos\flutter_image\src\out\ohos_debug_unopt_arm64, it will prompt failure src\out\ohos_debug_unopt_arm64\not found If the prompt cannot be found, it is to copy a copy from the ohos\har\in the project directory to the src\out\ohos_debug_unopt_arm64 directory, and then execute the previous step to succeed

2. Package the official package

flutter build hap --release or flutter build hap

If you need to specify the engine, use the --local-engine parameter, for example flutter build hap --release --local-engine=E:\ohos\flutter_image\src\out\ohos_release_arm64, and it will prompt failure src\out\ohos_release_arm64\not found. If the prompt cannot be found, it is to copy a copy from the ohos\har\in the project directory to the src\out\ohos_release_arm64 directory, and then execute the previous step to succeed

Frequently Asked Questions

Run flutter doctor Error: Unable to find git in your PATH. Execute the following command

git config --global --add  '*'

Summarize

This is the article about Hongmeng development and building a flutter-compatible development environment. For more information about Hongmeng construction, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!