DEV Community

Cover image for HarmonyOS Flutter Practice: 12-Use Simulator for Development and Debugging
shaohushuo
shaohushuo

Posted on

HarmonyOS Flutter Practice: 12-Use Simulator for Development and Debugging

Prerequisites

The development computer must be a Mac computer with an M series chip (ARM architecture)

Currently, Flutter Harmony development cannot use the X86 architecture simulator, only the ARM architecture simulator**

Create a project

After the development environment is successfully built, use the flutter create command to create a project

New project

flutter create --platforms ohos ohos_app
Enter fullscreen mode Exit fullscreen mode

Add support for the Harmony platform to the old project

flutter create --platforms ohos .
Enter fullscreen mode Exit fullscreen mode

Signature

Use DevEco to open the ohos directory in the above project, which is our Harmony project directory

Open File -> Project Structure..., click Siging Configs, check Automatically generate signature,

Click Sign In, log in to your Huawei account, and click Apply in the lower right corner, OK, signature completed.

Observe that the console will output the prompt Process finished with exit code 0

> hvigor WARN: The current module 'ohos' has dependency which is not installed at its oh-package.json5.
> hvigor Finished :entry:init... after 1 ms
> hvigor Finished ::init... after 1 ms

Process finished with exit code 0
Enter fullscreen mode Exit fullscreen mode

Create an emulator

  1. Open the Device Manager in DevEco (you can find it by pulling down from the left side of the run button in the upper right corner)

alt text

  1. Click + New Emulator in the lower right corner, and the emulator selection window will pop up. If the image has not been downloaded, a download button will appear in the box. Click Download first. After the download is complete, click Next to create the emulator, and then click Previous to create successfully

alt text

  1. Return to the simulator list window, the newly created simulator appears in the list, click the Run button, and the simulator runs successfully.

Sports Flutter Project

The simulator device should appear in the lower right corner of Vscode, such as 127.0.0.1:5555(ohos-arm64). If it does not appear, refer to the instructions in the precautions for operation 2.

Return to the Flutter project in Vscode, like the normal flutter project line, and click the Run button.

Notes

1. Flutter runs the App, the package is installed successfully, and the operation crashes. Check from the following aspects:

1.1 If it is an emulator of X86 computer architecture, try to delete the FloatingActionButton in main.dart

1.2 If the Flutter SDK uses ohos-3.22, try to turn off the impeller rendering method, open or create the file ohos/entry/src/main/resources/rawfile/buildinfo.json5, and add the following configuration

{
"string": [
{
"name": "enable_impeller",
"value": "true"
}
]
}
Enter fullscreen mode Exit fullscreen mode

2. The emulator device is not displayed in VSCode

2.1 Try to use Deveco to open the ohos directory of the project (that is, the Harmony project file) and wait for the initialization analysis to succeed

2.2 Try to restart VSCode

  1. When using fvm, flutter --version in the project directory The display is incorrect, not the ohos version

Try one by one in the following ways until success.

3.1 Try to run fvm use custom_3.22.0 in the vscode command line, wait for the command to create the .vscode/setting.json file and add a configuration similar to this

{
"dart.flutterSdkPath": ".fvm/versions/custom_3.22.0"
}
Enter fullscreen mode Exit fullscreen mode

A directory file such as .fvm/version/custom_3.22.0 appears in the project root directory, and a .fvmrc file appears in the project root directory, with contents similar to the following

{
"flutter": "custom_3.22.0"
}
Enter fullscreen mode Exit fullscreen mode

3.2 Try to restart the VsCode command line, or restart the entire VsCode. After reopening the VSCode command line, flutter --version will have the following output

Flutter 3.22.0-ohos • channel oh-3.22.0 • https://gitee.com/harmonycommando_flutter/flutter.git
Framework • revision 85630b0330 (13 days ago) • 2024-10-26 02:39:47 +0000
Engine • revision f6344b75dc
Tools • Dart 3.4.0 • DevTools 2.34.1
Enter fullscreen mode Exit fullscreen mode

3.3 Turn off global flutter configuration

In ~/.zshrc or ~/.bash_profile, delete or comment out configurations like this, and restart the command line/VSCode

#export PATH="/Users/zacksleo/flutter/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)