Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

Android 原生项目集成Flutter,运行打开FlutterActivity时闪退

按照官方手动集成步骤在原生项目中集成Flutter,编译正常,但是在打开 FlutterActivity 时 App 闪退。

Logcat日志如下:

E/flutter: [ERROR:flutter/runtime/dart_vm_data.cc(18)] VM snapshot invalid and could not be inferred from settings.
E/flutter: [ERROR:flutter/runtime/dart_vm.cc(250)] Could not setup VM data to bootstrap the VM from.
E/flutter: [ERROR:flutter/runtime/dart_vm_lifecycle.cc(84)] Could not create Dart VM instance.
A/flutter: [FATAL:flutter/shell/common/shell.cc(274)] Check failed: vm. Must be able to initialize the VM.
    

请问这是怎么一回事,应该如何解决?

> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel dev, 1.26.0-8.0.pre, on Mac OS X 10.15.7 19H2 darwin-x64,
    locale zh-Hans-CN)
[?] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[?] Xcode - develop for iOS and macOS (Xcode 12.3)
[?] Android Studio (version 4.1)
[?] IntelliJ IDEA Ultimate Edition (version 2018.3.2)
[?] VS Code (version 1.52.1)
[?] Connected device (1 available)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我已找到解决该问题的方法:原生Android项目集成Flutter Module踩坑记录

解决思路:
首先参考Flutter与Android混合编码配置笔记

可见该问题出现在 多变体多构建模式 项目中,上面的解决方案都不能正确解决问题。

参考这篇问答Flutter - Support build of multiple BuildTypes,我们可以推断出 Flutter 当前是不支持多构建模式的,仅支持的三种构建模式,分别是debugprofilerelease

但是我们的原生Android 项目是基于多构建模式实现的多衍生版本,显然从多构建模式重构到只使用变体实现多衍生需要做大量的工作。

我们可以是用一种取巧的方式来实现在当前原生项目中集成Flutter,那就是直接修改 flutter.gradle 文件,手动的添加我们当前项目使用的 buildtypes 即可。

搜索 project.android.buildTypes 定位到代码块,在代码块内添加自己的 buildtypes,在调试阶段使用 initWith debug,在最终出品时修改为 initWith release


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...