platform_view_detach_lifecycle_module_demo_2:基于 OpenHarmony Flutter 的 Add-to-App 问题复现项目

platform_view_detach_lifecycle_module_demo_2

Branch1Tags0

platform_view_detach_lifecycle_module_demo

OpenHarmony Flutter add-to-app demo for reproducing issue #1925 style fast route switching around FlutterPage + OhosView.

The host app is an ArkUI app under .ohos/entry. It opens a native ArkUI detail page, embeds FlutterPage, and the Flutter module renders an OhosView backed by DetachLifecyclePlatformViewPlugin.

What This Demo Checks

The risky lifecycle order is:

Native ArkUI Home
  -> FlutterDetail ArkUI page
    -> FlutterPage XComponent
      -> Flutter module
        -> OhosView / PlatformView
  -> back to Native ArkUI Home
  -> quickly open FlutterDetail again

On an unfixed 3.35 release embedding, a stale XComponent destroy callback can detach the current Flutter surface during fast route replacement. In local testing this demo reproduced a native crash in com.example.integration_test with a libflutter.so stack after rapid open/back cycles.

Project Layout

.ohos/entry
  Native ArkUI host app and stress controls.

.ohos/flutter_module
  Flutter module HAR and the PlatformView plugin.

lib/main.dart
  Flutter module page with OhosView content.

Configure Flutter

Use a local OHOS Flutter checkout. For example, if the checkout sits next to this repository:

../flutter_flutter/bin/flutter --version

If you prefer FVM, configure it locally after cloning:

fvm use /path/to/flutter_flutter --force

When validating local ETS changes in flutter_flutter, make sure the demo is actually consuming a regenerated local @ohos/flutter_ohos debug HAR. Do not trust stale .ohos/oh_modules contents.

Generated local embedding overrides, oh_modules, build outputs, logs, and temporary symlinks are intentionally ignored and should not be committed.

Build And Run

../flutter_flutter/bin/flutter analyze
../flutter_flutter/bin/flutter build hap --debug --no-pub
hdc -t 127.0.0.1:5555 install -r build/ohos/hap/entry-default-signed.hap
hdc -t 127.0.0.1:5555 shell aa start -b com.example.integration_test -m entry -a EntryAbility

Manual Scenario

  1. Launch the app.
  2. Tap Open Flutter Module Detail.
  3. Confirm the Flutter module page covers the native placeholder.
  4. Tap the native back button or use system back.
  5. Reopen the Flutter detail page several times.

The blue panel is the native PlatformView rendered through the Flutter module. The red area is a native placeholder behind FlutterPage; it should normally be covered by Flutter content.

Fast Stress Scenario

Tap Run Issue #1925 Stress on the native home page.

The app will run 50 fast cycles:

open FlutterDetail after 80 ms
auto back from FlutterDetail after 120 ms
repeat until Issue #1925 stress: 50/50

Useful checks:

hdc -t 127.0.0.1:5555 shell pidof com.example.integration_test
hdc -t 127.0.0.1:5555 shell ls -lt /data/log/faultlog/faultlogger | head
hdc -t 127.0.0.1:5555 shell hilog -x -v time | grep ISSUE-1925

Expected fixed result:

Flutter detail opens: 50
Issue #1925 stress: 50/50

The app process should still be alive and no new cppcrash-com.example.integration_test faultlog should appear.

Observed unfixed 3.35 release result in local testing:

cppcrash-com.example.integration_test-...log
Reason: Signal: SIGABRT
top frames: libflutter.so

Lifecycle Logs

Filter logs with:

hdc -t 127.0.0.1:5555 shell hilog -v time | grep OHOS-PV-MODULE

Each open/back cycle should produce paired PlatformView callbacks:

[OHOS-PV-MODULE] CALLBACK onFlutterViewAttached ...
[OHOS-PV-MODULE] CALLBACK onFlutterViewDetached ...

During the fast stress loop, issue-specific markers are emitted:

[OHOS-PV-MODULE] [ISSUE-1925] stress start target=50
[OHOS-PV-MODULE] [ISSUE-1925] auto back from FlutterDetail completed=50/50
[OHOS-PV-MODULE] [ISSUE-1925] stress finished completed=50

Introduction

platform_view_detach_lifecycle_module_demo_2

Customize your domain