flutter混合开发运行报错:VM snapshot must be valid. /Check failed: vm. Must be able to initialize the VM.

在现有android项目中集成flutter时,运行host app发生崩溃:

VM snapshot must be valid. 
Check failed: vm. Must be able to initialize the VM.

找遍了google和flutter github的issue, 目前发现的可行解决办法如下: 1.在flutter module的build文件的android节点添加:

project.android.libraryVariants.all { variant ->
    def targetAssets = "${project.buildDir}/intermediates/flutter/${variant.name}"
    def customSourceSet = variant.getSourceSets()[0]
    if (customSourceSet instanceof com.android.build.gradle.internal.api.DefaultAndroidSourceSet) {
        customSourceSet = (DefaultAndroidSourceSet)customSourceSet
        customSourceSet.getAssets().srcDirs(targetAssets)
    }
}

2.修改flutter_sdk目录下packages/flutter_tools/gradle/flutter.gradle:

change
variant.outputs[0].processResources.dependsOn(copyFlutterAssetsTask)
to
variant.outputs[0].processResources.dependsOn(flutterTask)

对比apk发现,assets文件夹下缺少flutter_shared或者flutter_assets会导致以上崩溃:

在这里插入图片描述

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券