可用于构建能在 OpenHarmony 设备上运行的 Flutter 引擎程序,支持 Linux、MacOS 构建及 Windows 生成 gen_snapshot,提供便捷构建脚本与环境配置指导,适配多平台与不同编译模式。【此简介由AI生成】
| Files | Last commit | Last update |
|---|---|---|
| 10 months ago | ||
| 10 months ago | ||
| 2 years ago | ||
| 1 year ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 1 year ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 3 years ago | ||
| 2 years ago | ||
| 1 year ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 2 years ago | ||
| 1 year ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 2 years ago | ||
| 3 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 9 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 3 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 3 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 1 year ago | ||
| 3 years ago | ||
| 7 years ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 2 years ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 2 years ago |
Flutter Engine
Source of the original repository: https://github.com/flutter/engine
Repository Description
This repository is an extension of the Flutter engine repository. It enables Flutter engine to run on OpenHarmony devices.
How to Build
- Build environment:
- Linux or macOS that support Flutter engine; Windows that supports gen_snapshot.
- Access to the allowed_hosts field in the DEPS_ohos file.
- Build steps:
-
Set up a basic environment. For details, see the official document.
The following libraries need to be installed:
sudo apt install python3 sudo apt install pkg-config sudo apt install ninja-buildFor Windows: Refer to the section "Compiling for Windows" in the official document.
-
Configure the file. Specifically, create an empty folder engine, create the .gclient file in this folder, and edit the file.
solutions = [ { "managed": False, "name": "src/flutter", "url": "git@gitcode.com:openharmony-sig/flutter_engine.git@oh-3.22.0", "custom_deps": {}, "deps_file": "DEPS_ohos", "safesync_url": "", }, ] -
Synchronize the code. In the engine directory, execute
gclient sync. The engine source code and packages repository will be synchronized, and the ohos_setup task will be executed. -
Download the SDK. Download the supporting development kits from HarmonyOS SDK. Suites downloaded from other platforms are not supported.
# Environment variables to set: HarmonyOS SDK, ohpm, hvigor, and node. export TOOL_HOME=/Applications/DevEco-Studio.app/Contents # macOS environment 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 -
Start building. In the engine directory, execute
./ohosto start building the Flutter engine that supports ohos devices. Starting from version 3.22.0, the engine compilation will by default compile both thelocal-engineandlocal-host-engine. When the SDK specifies local compiled artifacts, it must specify both of these compiled artifacts. For example:flutter build hap --target-platform ohos-arm64 --release --local-engine=<DIR>/engine/src/out/ohos_release_arm64/ --local-engine-host=<DIR>/engine/src/out/host_release -
Update the code. In the engine directory, execute
./ohos -b master.
FAQs
-
The message
Permission deniedis reported.
Executechmod +x < script file >to add the execution permission. -
To compile the engine in debug, release, or profile mode, execute
./ohos -t debug,./ohos -t release, or./ohos -t profile, respectively. -
To find the help, execute
./ohos -h. -
Different ways for handling newline characters by Windows, macOS, and Linux will cause different results of dart vm snapshot hash when installing the dart patches. You can obtain the value of snapshot hash through the following method:
python xxx/src/third_party/dart/tools/make_version.py --format='{{SNAPSHOT_HASH}}'Here, xxx is the engine path you created.
If the obtained value is not 8af474944053df1f0a3be6e6165fa7cf, check whether all lines of the xxx/src/third_party/dart/runtime/vm/dart.cc file and the xxx/src/third_party/dart/runtime/vm/image_snapshot.cc file end with LF. For Windows, you can use Notepad++ to check; for other systems, consult specific methods on your own.
-
After modifying the embedding layer code, running
./ohosdoes not take effect. You need to modify the timestamp of any file in the C++ layer for the build system to recognize it (e.g., add a space in any C++ file, save it, then remove the space and save again). Re-run the build to trigger the embedding layer to be repackaged. -
Configure automatic code navigation
It is recommended to use the
vscode+clangdplugin (note: it conflicts with C/C++ IntelliSense). Example configuration:"clangd.path": "./src/flutter/buildtools/linux-x64/clang/bin/clangd", "clangd.arguments": [ "--compile-commands-dir=./src/out/ohos_release_arm64/", "--query-driver=./src/flutter/buildtools/linux-x64/clang/bin/clang++" ], "C_Cpp.intelliSenseEngine": "disabled", -
gclient syncerror on WindowsKey error message:
'A required privilege is not held by the client'Solution: Go to Settings -> Developer Options -> Enable "Developer Mode"
Code Building at the Embedding Layer
-
Edit shell/platform/ohos/flutter_embedding/local.properties as follows:
sdk.dir=<OpenHarmony SDK directory> nodejs.dir=<nodejs SDK directory> -
Copy the file to
shell/platform/ohos/flutter_embedding/flutter/libs/arm64-v8a/from the builtenginedirectory.- For the debug or release version, copy
libflutter.so. - For the profile version, copy
libflutter.soandlibvmservice_snapshot.so.
- For the debug or release version, copy
-
In the shell/platform/ohos/flutter_embedding directory, execute the following instruction:
# buildMode can be set to debug, release, or profile. hvigorw --mode module -p module=flutter@default -p product=default -p buildMode=debug assembleHar --no-daemon -
Find the HAR file from the path
shell/platform/ohos/flutter_embedding/flutter/build/default/outputs/default/flutter.har.
If you are using DevEco Studio of a Beta version and encounter the error message must have required property 'compatibleSdkVersion', location: build-profile.json5:17:11 when building the project, refer to the section "Configuring Plugins" in chapter 6 "Creating a Project and Runing Hello World" of DevEco Studio Environment Setup.docx to modify the shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 file.
Introduction
可用于构建能在 OpenHarmony 设备上运行的 Flutter 引擎程序,支持 Linux、MacOS 构建及 Windows 生成 gen_snapshot,提供便捷构建脚本与环境配置指导,适配多平台与不同编译模式。【此简介由AI生成】
Customize your domain