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

Add flutter to exiting app project crash

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

本人Flutter菜鸟遵照官方指式,试着在已有的一个Android项目中添加Flutter Module,但是很不幸的失败了,log给予了我以上的信息,大意是虚拟无法初始化了。问题是我啥也没有干啊。添加Flutter到已有的项目怎么就crash了呢。
所以这一天就这么丧的开始了。

所以我开始Google了,搜了一下在issues里面看到这么一条,
https://github.com/flutter/flutter/issues/19818。

@kimlet is right. The main reason for E/flutter: [ERROR:flutter/runtime/dart_vm.cc(259)] VM snapshot must be valid. is missing of flutter_assets. For my case, I temporarily get around this matter by doing folowing steps (I use MacOS):

  1. run ./gradlew assemble inside .android.
  2. go to .android/Flutter/build/outputs/aar/, copy a proper aar file (there're some aar file for debug, release and profile), extract it with unzip command and copy flutter_asssets in extracted folder.
  3. create assets folder inside my existing Android project, paste fluter_assets there. Done!

The reason of why flutter doesn't pack flutter_assets to output apk file in my case is still unexplained. It's even more curious when I create a new dummy android project and try to add flutter module to it. It works well. I guess that my real project has some problems in gradle config that causes flutter ignoring flutter_assets

这位大哥的意思就是,我也不知道为什么,module里面的东西就是复制不到android项目里面去,所以我就自己动手了。在项目里面,新建了一个asssets文件夹,然后把aar里面的东西解压后复制过去。我试了下,在debug模式下是可以的,但是在release模式下依然还是很丧啊,那熟悉的crash拂面而来啊。

于是乎我想,既然是gradle的问题,那配下gradle不就完了嘛,奈何知识点不够,那只有继续问google了。幸运的是又一个哥们的一条记录,https://github.com/flutter/flutter/pull/25727,拯救了我,他做了个啥呢,把gralde改了下,现在意思是可以把assets复制过去了,但是现在应该只是在master分支上merge过去了。对于初学者来说,稳不稳定不重要,重要的是让自己的项目能release出去。不然领导问题这个星期干了啥,我说努力让项目跑起来,结果会很残忍的。
flutter channel master,切过去了,然后flutter,开始下载,Building flutter tool...,就这样大概一个晚上过去了。

Failed to retrieve the Dart SDK from: https://storage.googleapis.com/flutter_infra/flutter/9daf5c8d213aeb6c90712dd4b5fb9732b76bf39c/dart-sdk-darwin-x64.zip
If you're located in China, please see this page:
https://flutter.io/community/china
导入这两个镜像,之后的一切都很顺畅
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

下载完,然后再去跑项目,很是期待,然后依然是那张熟悉的脸。想了想是不是我姿势不对,然后就去flutter项目,clean啊,然后gradle assemble,然后失败了。失败了那就对了,这个项目是旧版本flutter新建的啊,所以只好重新新建一个flutter项目。

最后,成功了,VM snapshot must be valid.
Check failed: vm. Must be able to initialize the VM.再见了。

你可能感兴趣的:(VM snapshot must be valid. Check failed: vm. Must be able to initialize the VM.)