FlutterEngine crash when initiated inside on-demand dynamic feature
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
### Steps to reproduce
Hi, I'm experiencing an issue with dynamic features for [Android](https://developer.android.com/guide/playcore/feature-delivery) , in particular for those ones on demand. I'm trying to include the flutter framework into my feature(as module) then I'm installing at runtime as on demand feature. The problem is that when I've installed the module successfully, the app crashes because the FlutterEngine is not finding the libflutter.so. If I restart the app after that crash, It's working fine, the FlutterEngine retrieves all the references.
Code on app activity:
`
...
SplitInstallHelper.loadLibrary(context, "flutter.so")
...
`
Code on dynamic feature module:
```
val engine = FlutterEngine(context).apply {
this.dartExecutor.executeDartEntrypoint(
DartExecutor.DartEntrypoint(
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
it.name
), listOf(it.getChannelName())
)
}
```
Stacktrace:
```
[ERROR:flutter/runtime/dart_vm_data.cc(20)] VM snapshot invalid and could not be inferred from settings.
[ERROR:flutter/runtime/dart_vm.cc(270)] Could not set up VM data to bootstrap the VM from.
[ERROR:flutter/runtime/dart_vm_lifecycle.cc(85)] Could not create Dart VM instance.
Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6a8 in tid 2668 (exampleappandroid), pid 2668 (exampleappandroid)
Cmdline: exampleApp
pid: 2668, tid: 2668, name: exampleappandroid >>> exampleApp <<<
NOTE: Function names and BuildId information is missing for some frames due
NOTE: to unreadable libraries. For unwinds of apps, only shared libraries
NOTE: found under the lib/ directory are readable.
NOTE: On this device, run setenforce 0 to make the libraries readable.
NOTE: Unreadable libraries:
NOTE: /data/data/exampleApp/files/splitcompat/1/native-libraries/dfondemand.config.arm64_v8a/libflutter.so
#00 pc 000000000045e0a4 /data/data/exampleApp/files/splitcompat/1/native-libraries/dfondemand.config.arm64_v8a/libflutter.so
#06 pc 00000000002264b4 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterJNI.performNativeAttach+0)
#11 pc 00000000002265d0 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterJNI.attachToNative+0)
#16 pc 0000000000225f74 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.attachToJni+0)
#21 pc 0000000000225c20 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#27 pc 0000000000225bf4 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#33 pc 0000000000225bcc /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#39 pc 0000000000225eb0 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#45 pc 0000000000225ba8 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#50 pc 0000000000003424 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (com.exampleapp.custom_wrapper.FLViewModel.preWarm$lambda$2$lambda$1+0)
#55 pc 0000000000003334 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (com.exampleapp.custom_wrapper.FLViewModel.$r8$lambda$wOc_uQG1H2g-_BLj8KH5wOg632o+0)
#60 pc 00000000000032e8 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (com.exampleapp.custom_wrapper.FLViewModel$$ExternalSyntheticLambda0.run+0)
```
### Expected results
App that successfully runs the module including flutter framework installed at runtime
### Actual results
App crashing while initiating FlutterEngine
### Code sample
Code sample
```dart
import 'package:flutter/material.dart';
import 'package:flutter_module_a/main.dart' as ModuleA;
import 'package:flutter_module_b/main.dart' as ModuleB;
void main() => runApp(const MyApp());
@pragma('vm:entry-point')
void moduleA() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const ModuleA.MyApp());
}
@pragma('vm:entry-point')
void moduleB() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const ModuleB.MyApp());
}
```
### Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
### Logs
Logs
```console
[ERROR:flutter/runtime/dart_vm_data.cc(20)] VM snapshot invalid and could not be inferred from settings.
[ERROR:flutter/runtime/dart_vm.cc(270)] Could not set up VM data to bootstrap the VM from.
[ERROR:flutter/runtime/dart_vm_lifecycle.cc(85)] Could not create Dart VM instance.
Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6a8 in tid 2668 (exampleappandroid), pid 2668 (exampleappandroid)
Cmdline: exampleApp
pid: 2668, tid: 2668, name: exampleappandroid >>> exampleApp <<<
NOTE: Function names and BuildId information is missing for some frames due
NOTE: to unreadable libraries. For unwinds of apps, only shared libraries
NOTE: found under the lib/ directory are readable.
NOTE: On this device, run setenforce 0 to make the libraries readable.
NOTE: Unreadable libraries:
NOTE: /data/data/exampleApp/files/splitcompat/1/native-libraries/dfondemand.config.arm64_v8a/libflutter.so
#00 pc 000000000045e0a4 /data/data/exampleApp/files/splitcompat/1/native-libraries/dfondemand.config.arm64_v8a/libflutter.so
#06 pc 00000000002264b4 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterJNI.performNativeAttach+0)
#11 pc 00000000002265d0 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterJNI.attachToNative+0)
#16 pc 0000000000225f74 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.attachToJni+0)
#21 pc 0000000000225c20 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#27 pc 0000000000225bf4 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#33 pc 0000000000225bcc /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#39 pc 0000000000225eb0 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#45 pc 0000000000225ba8 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (io.flutter.embedding.engine.FlutterEngine.+0)
#50 pc 0000000000003424 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (com.exampleapp.custom_wrapper.FLViewModel.preWarm$lambda$2$lambda$1+0)
#55 pc 0000000000003334 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (com.exampleapp.custom_wrapper.FLViewModel.$r8$lambda$wOc_uQG1H2g-_BLj8KH5wOg632o+0)
#60 pc 00000000000032e8 /data/data/exampleApp/files/splitcompat/1/verified-splits/dfondemand.apk (com.exampleapp.custom_wrapper.FLViewModel$$ExternalSyntheticLambda0.run+0)
```
### Flutter Doctor output
Doctor output
```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.5 23F79 darwin-arm64, locale it-IT)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
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 installation is incomplete; a full installation is necessary for iOS and macOS development.
Download at: https://developer.apple.com/xcode/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
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
For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] IntelliJ IDEA Community Edition (version 2024.2.2)
[✓] VS Code (version 1.91.0)
[✓] Connected device (3 available)
[✓] Network resources
```
Contributor guide
Assessment
This issue has not been assessed yet.