CodeNewbie Community 🌱

Cover image for HarmonyOS Flutter in action: 02-Windows Environment Building Pit Guide
shaohushuo
shaohushuo

Posted on

HarmonyOS Flutter in action: 02-Windows Environment Building Pit Guide

Environment setup

1. Download the Flutter SDK and configure the environment variables

The HarmonyOS Flutter SDK needs to be downloaded from Gitee (https://gitcode.com/openharmony-sig/flutter_flutter). At this time, it is recommended to download the dev branch code.

The following user variables need to be configured

Note: HarmonyOS development requires Java to be installed and related variables configured

# Flutter SDK image
FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
# pub image
PUB_HOSTED_URL=https://pub.flutter-io.cn

DEVECO_SDK_HOME=C:Program FilesHuaweiDevEco Studiosdk
# Java SDK
JAVA_HOME=C:Program FilesHuaweiDevEco Studiojbr
Enter fullscreen mode Exit fullscreen mode

Configure environment variables

Edit PATH, add the following path, HarmonyOS development needs to configure ohpm, hvigor and node

C:Program FilesHuaweiDevEco Studiotoolsohpmbin

C:Program FilesHuaweiDevEco Studiotoolshvigorbin

C:Program FilesHuaweiDevEco Studiotoolsnode

C:Program FilesHuaweiDevEco Studiojbrbin
Enter fullscreen mode Exit fullscreen mode

After the SDK is downloaded and the environment variables are properly configured, use flutter doctor to check whether each item passes.

On the command line, run ohpm -v, hvigorw -v, node -v to see if it can be used, and make sure that the PATH configuration of each dependent tool is correct.

Use 'echo %DEVECO_SDK_HOME%', 'echo %JAVA_HOME%', etc. to check if the user variable is valid.

If the environment variables change, you need to restart the command-line tool.

In addition, it should be noted that the user environment variable is added first, if it is a system environment variable, you may need to log out or restart the system, otherwise the configuration may not take effect.

2. To avoid surprises, create a new project location and use the same disk as the SDK, such as drive D.

Otherwise, the package may not be found.

In addition, the project directory should not be too deep, otherwise the compilation may fail due to the path being too long.

3. VsCode doesn't recognize the device

Open the project with DevEco, and the device in Vscode should be ready to come out after the project analysis is complete.

4. The plugin Harry package could not be found

When I open the DevEco runtime, I get an error similar to the following

hpm ERROR: missing: flutter_inappwebview_ohos@/.../ohos/har/flutter_inappwebview_ohos.har, required by entry@1.0.0
ohpm ERROR: Found exception: Error: Fetch local file package error, /.../ohos/har/flutter_inappwebview_ohos.har does not exist., reached retry limit or non retryable error encountered.
ohpm ERROR: missing: video_player_ohos@/.../ohos/har/video_player_ohos.har, required by entry@1.0.0
ohpm ERROR: Found exception: Error: Fetch local file package error, /.../ohos/har/video_player_ohos.har does not exist., reached retry limit or non retryable error encountered.
ohpm ERROR: missing: path_provider_ohos@/.../ohos/har/path_provider_ohos.har, required by entry@1.0.0
ohpm ERROR: Found exception: Error: Fetch local file package error, /.../ohos/har/path_provider_ohos.har does not exist., reached retry limit or non retryable error encountered.
ohpm ERROR: missing: shared_preferences_ohos@/.../ohos/har/shared_preferences_ohos.har, required by entry@1.0.0
ohpm ERROR: Found exception: Error: Fetch local file package error, /.../ohos/har/shared_preferences_ohos.har does not exist., reached retry limit or non retryable error encountered.
ohpm ERROR: missing: image_picker_ohos@/.../ohos/har/image_picker_ohos.har, required by entry@1.0.0
ohpm ERROR: Found exception: Error: Fetch local file package error, /.../ohos/har/image_picker_ohos.har does not exist., reached retry limit or non retryable error encountered.
ohpm ERROR: missing: @ohos/flutter_ohos@/.../ohos/har/flutter.har, required by @
ohpm ERROR: Found exception: Error: Fetch local file package error, /.../ohos/har/flutter.har does not exist., reached retry limit or non retryable error encountered.
ohpm ERROR: Install failed, detail: Error: Fetch local file package error, /.../ohos/har/flutter_inappwebview_ohos.har does not exist.
Enter fullscreen mode Exit fullscreen mode

At this point, you need to run 'flutter run' or 'flutter build' under the Flutter project to generate the har package of the plugin

4. How to customize the display of the project name after DevEco opens ohos

For each HarmonyOS Flutter project, after opening the ohos project with DevEco, the default project name displayed is 'ohos', if you want to customize the displayed project name, you can refer to the following steps:

In the ohos/.idea directory, create a new '.name' file and write the project name.

Top comments (0)