Location>code7788 >text

Hongmeng access to Flutter 3.22

Popularity:688 ℃/2024-11-07 13:01:28

Configuring Environment Variables

  1. Configuring the HarmonyOS SDK and Environment Variables
  • API12, deveco-studio-5.0 or command-line-tools-5.0
  • Configuring Java17
  • Configure environment variables (SDK, node, ohpm, hvigor)
 export TOOL_HOME=/Applications//Contents # macmatrix
 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
  1. Download Flutter repository code via the code toolgit clone /harmonycommando_flutter/To do this, specify the dev or master branch, and configure the environment
 # Dependency Cache
 export PUB_CACHE=D:/PUB
 # rawflutter_flutter/bincatalogs
 export PATH=<flutter_flutter path>/bin:$PATH
 # Domestic mirrors
 export PUB_HOSTED_URL=
 export FLUTTER_STORAGE_BASE_URL=

 # HamonyOS SDK
 export TOOL_HOME=/Applications//Contents # macmatrix
 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

Construction Steps

  1. Run flutter doctor -v to check if the environment variables are configured correctly, Futter and OpenHarmony should both be ok, if there is a lack of environment in both places, follow the prompts to fill in the appropriate environment.
    img1
  2. Create a project with the compile command, and compile the product in the<projectName>/ohos/entry/build/default/outputs/default/Down.
 # Create Project
 flutter create --platforms ohos <projectName>

 # Go to the project root directory and compile
 # typical example:flutter build hap --release
 flutter build hap --release
  1. After discovering the ohos device via the flutter devices command, use hdc -t install Perform the installation.
  2. It can also be run directly using the following commands:
   # Example: flutter run -d <device-id>
   flutter run --debug -d <device-id>
  1. Build app package command:
 # typical example:flutter build app --release
 flutter build app --release

List of commands that are compatible with OpenHarmony development

command name command description Instructions for use
doctor Environmental testing flutter doctor
config Environment Configuration flutter config --"key" "value"
create Create a new project flutter create --platforms ohos,android,ios --org "org" "appName"
create Creating a module template flutter create -t module "moduleName"
create Creating a plugin template flutter create -t plugin --platforms ohos,android,ios "pluginName"
create Creating the plugin_ffi template flutter create -t plugin_ffi --platforms ohos,android,ios "pluginName"
devices Connected Device Finder flutter devices
install Application Installation flutter install -t "deviceId" "path to hap file"
assemble Resource Packaging flutter assemble
build Test Application Builds flutter build hap --debug
build Formal application building flutter build hap --release
run application running flutter run
attach debug mode flutter attach
screenshot capture an image displayed on a computer screen flutter screenshot

Attachment:Flutter Tripartite Library Adaptation Program

Running on a cell phone

In the project root directory, execute theflutter runThen you can run it on your cell phone. If you are connected to an Android cell phone, you can run it directly and check the effect on your cell phone. If you are connected to a Hongmeng NEXT phone, you need to configure the certificate first, the place to configure the certificate is atohos/build-profile.json5file, the certificate configuration is complete, you can directly directly run and view the results on the Hongmeng NEXT phone.
harmony
android
Packages under the Hongmeng platform ohos can be copied to other projects and used directly.

  • See gitee for the source code of this example.