Skip to content

Restructure ohos/ into proper OHOS Flutter HAR plugin layout with NAPI native support#344

Merged
wang-bin merged 8 commits into
masterfrom
copilot/add-ohos-support
Apr 14, 2026
Merged

Restructure ohos/ into proper OHOS Flutter HAR plugin layout with NAPI native support#344
wang-bin merged 8 commits into
masterfrom
copilot/add-ohos-support

Conversation

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Replaces the incorrect ohos/ files (which used the Linux/desktop Flutter EGL plugin API) with the correct OHOS Flutter HAR plugin layout.

New OHOS module structure

  • build-profile.json5 — module build config with externalNativeOptions pointing at the C++ CMakeLists, targeting arm64-v8a
  • hvigorfile.ts — Hvigor build script using import { harTasks } + export default { system: harTasks, plugins: [] } pattern
  • index.ets — re-exports FvpPlugin
  • oh-package.json5 — package descriptor with @ohos/flutter_ohos HAR dependency
  • src/main/module.json5 — HAR module descriptor (type: har)
  • local.properties — machine-local SDK path template (added to .gitignore)

ArkTS plugin (src/main/ets/components/plugin/FvpPlugin.ets)

Mirrors Android's FvpPlugin.java in ArkTS: implements FlutterPlugin + MethodCallHandler on channel "fvp", handling CreateRT / ReleaseRT / MixWithOthers. CreateRT registers an OHOS SurfaceTextureEntry, retrieves its surfaceId, sets the buffer size, then calls the native NAPI module:

const texId = textureRegistry.getTextureId();
const entry = textureRegistry.registerTexture(texId);
const surfaceId = entry.getSurfaceId();
textureRegistry.setTextureBufferSize(texId, width, height);
fvpNative.nativeSetSurface(handle, texId, surfaceId, width, height);

Native NAPI module (src/main/cpp/)

  • Registers the module via NAPI_MODULE(fvp_plugin, Init) macro
  • Exports nativeSetSurface — uses OH_NativeWindow_CreateNativeWindowFromSurfaceId() to bridge Flutter's surface ID to mdk's updateNativeSurface()
  • Exports MdkGetPlayerVid (returns OHNativeWindow*) and MdkIsEmulator for Dart FFI, marked with FVP_EXPORT (__attribute__((visibility("default")))) to ensure visibility despite hidden-by-default symbol preset
  • Compiles callbacks.cpp into the same .so
  • Links libace_napi.z.so, libace_ndk.z.so, libnative_window.so; pulls mdk via the existing cmake/deps.cmake
  • C++20, CMake 3.17

CMake / deps

  • cmake/deps.cmake: downloads mdk-sdk-ohos.7z for the OHOS target (via CMAKE_SYSTEM_NAME MATCHES "OHOS")

Dart

  • lib/src/video_player_mdk.dart: preferred OHOS video decoder set to "OH" (hardware decoder) instead of "AMediaCodec"

Copilot AI and others added 3 commits April 9, 2026 10:27
…set uri, decoders

Agent-Logs-Url: https://github.com/wang-bin/fvp/sessions/c80e2b02-02c3-461e-b42e-5d57a5c3fdaa

Co-authored-by: wang-bin <785206+wang-bin@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wang-bin/fvp/sessions/c80e2b02-02c3-461e-b42e-5d57a5c3fdaa

Co-authored-by: wang-bin <785206+wang-bin@users.noreply.github.com>
… native C++ NAPI support

Agent-Logs-Url: https://github.com/wang-bin/fvp/sessions/ef1c213b-5b60-48b4-99c5-c3c804e2db89

Co-authored-by: wang-bin <785206+wang-bin@users.noreply.github.com>
@wang-bin

Copy link
Copy Markdown
Owner

@copilot there is a working ohos app example using libmdk: https://github.com/wang-bin/mdk-examples/tree/master/ohos , please review current code by referring to the code in that link

Copilot AI and others added 2 commits April 14, 2026 07:33
… library links, abiFilters

Agent-Logs-Url: https://github.com/wang-bin/fvp/sessions/9d6b16e9-81aa-45a1-b44e-c689b61dad7f

Co-authored-by: wang-bin <785206+wang-bin@users.noreply.github.com>

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot there is a working ohos app example using libmdk: https://github.com/wang-bin/mdk-examples/tree/master/ohos , please review current code by referring to the code in that link

Reviewed against https://github.com/wang-bin/mdk-examples/tree/master/ohos and applied the following corrections (commit a0e8022):

fvp_plugin.cpp:

  • Replaced NAPI_MODULE macro (Node.js) with explicit static napi_module + napi_module_register + __attribute__((constructor)), matching the mdk-examples pattern
  • Added #include <hilog/log.h> and redirected MDK log output to OHOS HiLog via OH_LOG_Print (same approach as player_napi.cpp)
  • Replaced clog with FVP_LOG/FVP_ERR HiLog macros

src/main/cpp/CMakeLists.txt:

  • Downgraded cmake_minimum_required to 3.4.1 and C++ standard to 17 (matching mdk-examples)
  • Fixed wrong library name libnative_window.solibnativewindow.so
  • Added missing libace_ndk.z.so and libhilog_ndk.z.so
  • Removed the Android-only FLUTTER_PLUGIN_IMPL compile definition

build-profile.json5:

  • Added abiFilters: ["arm64-v8a", "x86_64"] and named target "fvp_plugin" in externalNativeOptions

Copilot AI requested a review from wang-bin April 14, 2026 07:37
@wang-bin

Copy link
Copy Markdown
Owner

@copilot only arm64-v8a is available. keep c++20. no cmake version change. no need to change log. copyright year is 2026

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot only arm64-v8a is available. keep c++20. no cmake version change. no need to change log. copyright year is 2026

Done in commit af06abd:

  • abiFilters is now ["arm64-v8a"] only
  • Reverted to C++20 and cmake_minimum_required(VERSION 3.10)
  • Removed the mdk::setLogHandler / HiLog changes; log output stays as clog
  • Copyright year updated to 2026

@wang-bin

Copy link
Copy Markdown
Owner

keep using NAPI_MODULE macro

@wang-bin

Copy link
Copy Markdown
Owner

@copilot preferred video decoder for ohos is "OH" not "AMediaCodec". symbols in fvp_plugin.h must be visible

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

keep using NAPI_MODULE macro

Done in commit 573aa9a — replaced the manual static napi_module + napi_module_register + __attribute__((constructor)) with NAPI_MODULE(fvp_plugin, Init).

@copilot preferred video decoder for ohos is "OH" not "AMediaCodec". symbols in fvp_plugin.h must be visible

Done in commit 573aa9a:

  • video_player_mdk.dart: changed OHOS decoder list to ['OH', 'FFmpeg', 'dav1d']
  • fvp_plugin.h: added FVP_EXPORT macro (__attribute__((visibility("default"))) on non-Windows) to MdkIsEmulator and MdkGetPlayerVid

@wang-bin

Copy link
Copy Markdown
Owner

@copilot libnative_window not libnativewindow. cmake min version 3.17. change modified files copyright year, ends with 2026. export { harTasks } is wrong. download mdk-sdk-ohos.7z

…s, mdk-sdk-ohos.7z

Agent-Logs-Url: https://github.com/wang-bin/fvp/sessions/d72442c9-83e4-43cc-bed3-8c4a9a5d85d7

Co-authored-by: wang-bin <785206+wang-bin@users.noreply.github.com>

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot libnative_window not libnativewindow. cmake min version 3.17. change modified files copyright year, ends with 2026. export { harTasks } is wrong. download mdk-sdk-ohos.7z

Done in commit 4f2242c:

  • libnative_window.so (corrected from libnativewindow.so)
  • cmake_minimum_required(VERSION 3.17)
  • hvigorfile.ts: now uses import { harTasks } from '@ohos/hvigor-ohos-plugin' + export default { system: harTasks, plugins: [] }
  • cmake/deps.cmake: mdk-sdk-ohos.7z (was mdk-sdk-ohos.tar.xz)
  • Copyright years updated to 2026 in FvpPlugin.ets and lib/src/lib.dart

@wang-bin wang-bin marked this pull request as ready for review April 14, 2026 15:58
@wang-bin wang-bin merged commit 37323ee into master Apr 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants