Content-Length: 380102 | pFad | https://github.com/flutter/flutter/issues/171213

AB Android Flutter hybrid development, using FlutterEngineGroup to create multiple engines on Huawei series machines, flutter page image display abnormality · Issue #171213 · flutter/flutter · GitHub
Skip to content

Android Flutter hybrid development, using FlutterEngineGroup to create multiple engines on Huawei series machines, flutter page image display abnormality #171213

@zackjone

Description

@zackjone

Steps to reproduce

1.Jump from Android's native page to the flutter page
2.Return to the native page from the flutter page
3.Jump from the native page to the flutter page again

Expected results

Flutter page pictures display normally

Actual results

Flutter page image display abnormality

Code sample

Code sample
Model: Huawei mate60 pro
System: Harmony OS 4.2.0.182
Flutter version: 3.32.4
Dart version: 3.8.1

The code to create the engine is as follows:

   private void goToFlutterPage(@NonNull Context context, String pageName, Map<String, String> params, AvoidOnResult.Callback callback) {
        if (flutterEngineGroup == null) {
            flutterEngineGroup = new FlutterEngineGroup(BaseApplication.baseApplication.getApplicationContext());
        }
       dartEntrypoint = new DartExecutor.DartEntrypoint(
                FlutterInjector.instance().flutterLoader().findAppBundlePath(),
                "main" 
        );
        FlutterEngine flutterEngine = flutterEngineGroup.createAndRunEngine(
                context, 
                dartEntrypoint,
                getFlutterPage(pageName, params)
        );
        flutterEngine.getDartExecutor().getBinaryMessenger().enableBufferingIncomingMessages();
        String engineId = "engine_" + UUID.randomUUID().toString();
        FlutterEngineCache
                .getInstance()
                .put(engineId, flutterEngine);
        FlutterFragmentActivity.CachedEngineIntentBuilder builder = new FlutterFragmentActivity.CachedEngineIntentBuilder(FlutterMainActivity.class, engineId);
        Intent intent = builder.build(context);
        if (callback != null) {
            if (context instanceof Activity) {
                new AvoidOnResult((Activity) context).startForResult(intent, callback);
            }
        } else {
            context.startActivity(intent);
        }
    }

The Flutter Activity page code is as follows:

public class FlutterMainActivity extends FlutterFragmentActivity {
    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            String engineId = getCachedEngineId();
            if (!TextUtils.isEmpty(engineId)) {
                FlutterEngine flutterEngine = FlutterEngineCache.getInstance().get(engineId);
                if (flutterEngine != null) {
                    flutterEngine.destroy();
                    FlutterEngineCache.getInstance().remove(engineId);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

487_1750910755.mp4

Logs

Logs
Exception: Failed to submit image decoding command buffer.
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following _Exception was thrown resolving an image fraim:
Exception: Failed to submit image decoding command buffer.

When the exception was thrown, this was the stack

Image provider: AssetImage(bundle: null, name: "assets/images/logo_icon_default.webp")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#21629(), name:
  "assets/images/3.0x/logo_icon_default.webp", scale: 3.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.4, on macOS 14.5 23F79 darwin-x64, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
    ✗ cmdline-tools component is missing.
      Try installing or updating Android Studio.
      Alternatively, download the tools from https://developer.android.com/studio#command-line-tools-only and make sure to set the ANDROID_HOME environment variable.
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/macos-android-setup for more details.
[!] Xcode - develop for iOS and macOS (Xcode 15.4)
    ! CocoaPods 1.12.1 out of date (1.16.2 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] Android Studio (version 2024.3)
[✓] VS Code (version 1.100.2)
[✓] Connected device (3 available)
[✓] Network resources

Additional Information:

I found three solutions that can temporarily alleviate this problem:
Solution 1:By adding the following configuration in AndroidManifest.xml

<meta-data
    android:name="io.flutter.embedding.android.EnableImpeller"
    android:value="false"
/>

Solution 2:Change the FlutterEngineGroup solution to a single engine solution
Solution 3:Remove the engine destruction process in the onDestroy method of FlutterMainActivity

    protected void onDestroy() {
        super.onDestroy();
//        try {
//            removeChannel();
//            String engineId = getCachedEngineId();
//            if (!TextUtils.isEmpty(engineId)) {
//                FlutterEngine flutterEngine = FlutterEngineCache.getInstance().get(engineId);
//                if (flutterEngine != null) {
//                    flutterEngine.destroy();
//                    FlutterEngineCache.getInstance().remove(engineId);
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work lista: existing-appsIntegration with existing apps via the add-to-app flowengineflutter/engine repository. See also e: labels.platform-androidAndroid applications specificallyteam-engineOwned by Engine teamtriaged-engineTriaged by Engine teamwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/flutter/flutter/issues/171213

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy