Repository: flutter
Issue: Crash on Add2App module implemented with Feature Delivery
Labels: c: crash,platform-android,engine,d: api docs,a: existing-apps,has reproducible steps,P2,found in release: 2.5,found in release: 2.6,team-android,triaged-android

Hi team!
We are working on a Flutter Add2App module implemented with [Feature Delivery](https://developer.android.com/guide/playcore/feature-delivery) on Android.
Working in a standard way (using a Universal APK), the implementation works fine both in debug and release mode
With the Module as Feature Delivery, the debug mode works fine but we have a crash on release mode.

The error:
```
2021-10-18 22:44:32.013 3549-3549/? E/flutter: [ERROR:flutter/runtime/dart_vm_data.cc(18)] VM snapshot invalid and could not be inferred from settings.
2021-10-18 22:44:32.013 3549-3549/? E/flutter: [ERROR:flutter/runtime/dart_vm.cc(256)] Could not set up VM data to bootstrap the VM from.
2021-10-18 22:44:32.013 3549-3549/? E/flutter: [ERROR:flutter/runtime/dart_vm_lifecycle.cc(84)] Could not create Dart VM instance.
2021-10-18 22:44:32.013 3549-3549/? A/flutter: [FATAL:flutter/shell/common/shell.cc(143)] Check failed: vm. Must be able to initialize the VM.
    
    
    --------- beginning of crash
2021-10-18 22:44:32.014 3549-3549/? A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 3549 (e.myapplication), pid 3549 (e.myapplication)
2021-10-18 22:44:32.102 3666-3666/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2021-10-18 22:44:32.102 3666-3666/? A/DEBUG: Build fingerprint: 'xiaomi/jasmine/jasmine_sprout:10/QKQ1.190910.002/V11.0.28.0.QDIMIXM:user/release-keys'
2021-10-18 22:44:32.102 3666-3666/? A/DEBUG: Revision: '0'
2021-10-18 22:44:32.102 3666-3666/? A/DEBUG: ABI: 'arm64'
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG: Timestamp: 2021-10-18 22:44:32-0300
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG: pid: 3549, tid: 3549, name: e.myapplication  >>> com.example.myapplication <<<
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG: uid: 10733
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG: signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG: Abort message: '[FATAL:flutter/shell/common/shell.cc(143)] Check failed: vm. Must be able to initialize the VM.
    '
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     x0  0000000000000000  x1  0000000000000ddd  x2  0000000000000006  x3  0000007fd73314a0
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     x4  0080000000000000  x5  0080000000000000  x6  0080000000000000  x7  0000000000008000
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     x8  00000000000000f0  x9  d7a24bb0d6b503cb  x10 0000000000000001  x11 0000000000000000
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     x12 fffffff0fffffbdf  x13 0000000000000003  x14 0000000000000001  x15 0000818454d48122
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     x16 00000076f28f58c0  x17 00000076f28d1900  x18 00000076f4560000  x19 0000000000000ddd
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     x20 0000000000000ddd  x21 00000000ffffffff  x22 0000007fd7332920  x23 0000000000000000
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     x24 0000007fd7332960  x25 0000007fd7332f28  x26 0000000000000000  x27 0000000000000003
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     x28 0000007fd7333270  x29 0000007fd7331540
2021-10-18 22:44:32.130 3666-3666/? A/DEBUG:     sp  0000007fd7331480  lr  00000076f28830c4  pc  00000076f28830f0
2021-10-18 22:44:32.455 3666-3666/? A/DEBUG: backtrace:
2021-10-18 22:44:32.455 3666-3666/? A/DEBUG:       #00 pc 00000000000830f0  /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: cf739dbc84bcc78f7a1500721bfb3758)
2021-10-18 22:44:32.455 3666-3666/? A/DEBUG:       #01 pc 0000000000007914  /data/data/com.example.myapplication/files/splitcompat/1/native-libraries/dynamicfeature.config.arm64_v8a/libflutter.so
```

## Steps to Reproduce

We created this [public repo](https://github.com/ldasilva-net/feature_delivery_flutter) with the minimum case. It's a simple flutter module (`flutter create -t module --org com.example my_flutter_module`) and an Android app with a Feature delivery module (containing Flutter).

1. Clone repo.
2. In `my_flutter_module` run `flutter build aar`
3. In `android_project/settings.gradle` replace  `url '<LOCAL_FLUTTER_MAVEN>'` with the Flutter local maven repository provided on first step build.
4. Open the Android Project, sync, switch variant to `release` and create a Bundle.
5. In the generated Bundle directory, run:
```
bundletool build-apks --local-testing --bundle=app-release.aab --output=app-release.apks
bundletool install-apks --apks=app-release.apks
```

**Expected results:** 

https://user-images.githubusercontent.com/11092091/137834106-ca213d4a-b0ad-4fac-bfaf-8268f8c66a51.mp4

1. First screen: Tap on the first button to simulate download the feature.
2. First screen: Wait a second (sometimes the process to simulate the installation needs it) and then tap on the second button to launch an Activity from the Feature Module through an Intent. 
3. Second screen: This is an Activity that lives in the Feature delivery module. It contains a button for launch a `FlutterActivity`. Tap it. In release mode, we have an error.
4. Third screen: A Flutter screen, the hello world counter. 

**Actual results:**
On release mode, when we launch Flutter we have a crash.

`flutter doctor -v`

```
[✓] Flutter (Channel stable, 2.5.2, on macOS 11.5.2 20G95 darwin-arm, locale en-US)
    • Flutter version 2.5.2 at /Users/ldasilva/dev/sdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3595343e20 (3 weeks ago), 2021-09-30 12:58:18 -0700
    • Engine revision 6ac856380f
    • Dart version 2.14.3

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/ldasilva/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = /Users/ldasilva/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.61.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.27.0

[✓] Connected device (2 available)
    • Mi A2 (mobile) • 45b6896 • android-arm64  • Android 10 (API 29)
    • Chrome (web)   • chrome  • web-javascript • Google Chrome 94.0.4606.81

• No issues found!
```