当前位置:   article > 正文

集成Flutter到现有项目时报 Check failed: vm. Must be able to initialize the VM 解决方案_flutter check failed

flutter check failed

添加Flutter项目到原有项目时会报Check failed: vm. Must be able to initialize the VM.

 

这个问题的是因为flutter相关的assets没有合并过来,原因是flutter.gradle合并assets文件是通过module名称查找合并的,而原来我的项目的主module名字不叫app

解决方案:修改主项目的Module的名字为app

查了一下网上给出的解决方案都是

1.在flutter module的build文件的android节点添加:

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

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

  1. change
  2. variant.outputs[0].processResources.dependsOn(copyFlutterAssetsTask)
  3. to
  4. variant.outputs[0].processResources.dependsOn(flutterTask)

在flutter_tools/gradle/flutter.gradle里面

 

这里flutter合并资源是通过 mainModuleName = "app" 来合并的,然而原来我主项目的module名字不叫app,所以会出现找不到assets问题,这里挺坑的module只能为app

           

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/515339
推荐阅读
相关标签
  

闽ICP备14008679号