赞
踩
添加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节点添加:
-
- 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)
在flutter_tools/gradle/flutter.gradle里面
这里flutter合并资源是通过 mainModuleName = "app" 来合并的,然而原来我主项目的module名字不叫app,所以会出现找不到assets问题,这里挺坑的module只能为app
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。