美文网首页
flutter混合开发运行报错:VM snapshot must

flutter混合开发运行报错:VM snapshot must

作者: 山水相逢z | 来源:发表于2019-01-02 15:21 被阅读159次

    在现有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会导致以上崩溃:


    在这里插入图片描述

    相关文章

      网友评论

          本文标题:flutter混合开发运行报错:VM snapshot must

          本文链接:https://www.haomeiwen.com/subject/hrmzlqtx.html