在现有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会导致以上崩溃:
在这里插入图片描述
网友评论