Skip to content

[Flutter GPU] --enable-flutter-gpu CLI flag is ignored on Android #186297

Description

@bdero

Steps to reproduce

  1. Create a fresh Flutter app and add a dependency that touches flutter_gpu on the first frame (e.g. flutter_scene). Any access to gpu.gpuContext triggers the runtime check.
  2. Connect an Android device with Vulkan-Impeller support (reproduced on Pixel 10 Pro, Android 16 / API 36).
  3. Run with the documented opt-in flag, without adding any manifest metadata:
    flutter run -d <android-device> --enable-flutter-gpu --enable-impeller

Expected results

The app launches with Flutter GPU enabled, matching the runtime error message which lists --enable-flutter-gpu as a valid way to opt in (engine/src/flutter/lib/gpu/context.cc:53–58):

Flutter GPU must be enabled via the Flutter GPU manifest setting. This can be done either via command line argument --enable-flutter-gpu or by adding the FLTEnableFlutterGPU key set to true in the Info.plist on iOS/macOS, or the io.flutter.embedding.android.EnableFlutterGPU metadata key to true in the AndroidManifest.xml on Android.

…and matching the documented behavior on iOS/macOS where the CLI flag alone is sufficient.

Actual results

The app throws:

Exception: Flutter GPU must be enabled via the Flutter GPU manifest setting. This can be done
either via command line argument --enable-flutter-gpu or by adding the FLTEnableFlutterGPU
key set to true in the Info.plist on iOS/macOS, or the
io.flutter.embedding.android.EnableFlutterGPU metadata key to true in the AndroidManifest.xml
on Android.

repeatedly on every frame, because dart_state->IsFlutterGPUEnabled() returns false (engine/src/flutter/lib/gpu/context.cc:51).

Adding the manifest opt-in to android/app/src/main/AndroidManifest.xml works around it:

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

Test matrix

Same minimal app, no FLTEnableFlutterGPU in Info.plist, no EnableFlutterGPU in AndroidManifest.xml unless noted.

Platform CLI flag Manifest/plist key Result
macOS --enable-flutter-gpu none ✅ Flutter GPU enabled
macOS (none) none ❌ Runtime exception (expected)
iOS --enable-flutter-gpu none ✅ Flutter GPU enabled
iOS (none) none ❌ Runtime exception (expected)
Android --enable-flutter-gpu none ❌ Runtime exception (bug)
Android (none) EnableFlutterGPU=true ✅ Flutter GPU enabled
Android --enable-flutter-gpu EnableFlutterGPU=true ✅ Flutter GPU enabled

So the CLI flag enables the API on iOS and macOS but not Android.

Where it diverges

  • iOS: FlutterDartProject.mm:226–228 reads the Info.plist key. The --enable-flutter-gpu switch also reaches settings.enable_flutter_gpu via the cross-platform path in shell/common/switches.cc:553, so either path works.
  • macOS: FlutterDartProject.mm:97 reads the Info.plist key, plus the cross-platform switch path. Either works.
  • Android: FlutterEngineFlags.java:232 defines new Flag(\"--enable-flutter-gpu\", \"EnableFlutterGPU\", true); and FlutterLoader reads the EnableFlutterGPU manifest meta-data and converts it into the --enable-flutter-gpu engine switch. The flutter run --enable-flutter-gpu argument from the tool side does not appear to flow through to the engine's switch list, so settings.enable_flutter_gpu stays false.

Suggested fix

Make flutter run --enable-flutter-gpu propagate to the Android engine launch (add it to the engine arg list the tool passes to FlutterLoader / the activity) so the documented behavior is consistent with iOS/macOS.

Flutter version

Flutter 3.44.0-1.0.pre-380
Tools • Dart 3.13.0

Reproducible on the master channel; the code paths cited above are current.

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Bug.

Projects

Status
✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions