美文网首页
Flutter混合开发iOS集成填坑

Flutter混合开发iOS集成填坑

作者: LordLamb | 来源:发表于2019-04-21 19:50 被阅读0次

    Flutter因为优秀的跨平台开发效率受到很多开发者的青睐。对于大多数开发者来说,可能会优先考虑采用混合开发方案。Flutter也给出了混合开发的解决方案:Add Flutter to existing apps。这篇文档中已经给出了详细的解决方案,本文就不再赘述。本文主要介绍我在集成过程中踩过的坑和解决办法。

    1. 编译过程中环境变量找不到
    • FLUTTER_ROOT
      在~/.bash_profile中增加以下几行代码
    export FLUTTER_ROOT=${Your_Flutter_Install_Path}
    export PATH=$FLUTTER_ROOT/bin:$PATH
    

    然后执行source ~/.bash_profile

    • DART_SDK
      在~/.bash_profile中增加以下几行代码
    export DART_SDK=${FLUTTER_ROOT}/bin/cache/dart-sdk
    export PATH=${DART_SDK}/bin:$PATH
    

    然后执行source ~/.bash_profile

    • FLUTTER_APPLICATION_PATH
      在Run Script Phase之前加入这个变量的定义,完整的Script文件如下:
    export FLUTTER_APPLICATION_PATH=${Your_Flutter_Application_Path}
    "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
    "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
    
    1. 内存泄漏
      Flutter内存泄漏问题由来已久,手把手教你解决 Flutter engine 内存泄漏这篇文章介绍了如何解决内存泄漏问题,可能是我的使用方法不对,按照这篇文章的方法每次进入FlutterViewController之后还是发现会多一个Isolate,意味着还是会有内存泄漏。最后我将FlutterViewController封装成了一个单例解决了这个问题。但是这样解决会存在另外一个问题:FlutterViewController有多个route的时候,第二次进入的route不会刷新,解决方案在下面。

    2. 多个flutter route界面不刷新
      这个问题我参考了这个issue,但是发现写完以后并不能运行。然后查看了我的Flutter安装包,发现安装包这个目录下integration_tests并没有ios_add2app这个工程,查看GitHub上的Flutter代码发现master分支上是有这个工程的,所以决定升级Flutter,考虑到稳定性,只将Flutter升级到了beta版本。升级命令如下:

    flutter channel beta
    flutter upgrade
    

    升级之后可以参考integration_tests目录下的ios_add2app这个工程来修改代码了。

    最新的stable版本已经支持了这个功能

    1. Failed to find assets path for "flutter_assets"
      重新切换以下flutter channel即可
    flutter channel master
    flutter channel beta
    
    1. 上传App Store报错
      错误信息如下:
    ERROR ITMS-90087: “Unsupported Architectures. The executable for YourApp.app/Frameworks/Flutter.framework contains unsupported architecture ‘[x86_64]’”
    
    ERROR ITMS-90209: “Invalid Segment Alignment. The app binary at ‘YourApp.app/Frameworks/Flutter.framework/Flutter’ does not have proper segment alignment. Try rebuilding the app with the latest Xcode version.”
    
    ERROR ITMS-90125: “The binary is invalid. The encryption info in the LC_ENCRYPTION_INFO load command is either missing or invalid, or the binary is already encrypted. This binary does not seem to have been built with Apple’s linker.”
    
    WARNING ITMS-90080: “The executable ‘Payload/YourApp.app/Frameworks/Flutter.framework’ is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables. For more information refer to Technical Q&A QA 1788 - Building a Position Independent Executable in the iOS Developer Library.”
    

    解决方案:
    在Xcode Build Phase的Run Script Phase最下面新增一行:

    "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" thin
    
    1. 'Flutter/Flutter.h' file not found
      在Flutter工程目录下执行flutter run,之后在iOS工程执行pod install,重新编译iOS主工程

    2. 新增image不显示
      在Flutter工程下执行

    flutter packages upgrade
    flutter run
    

    之后在iOS工程执行pod install,重新编译iOS主工程

    相关文章

      网友评论

          本文标题:Flutter混合开发iOS集成填坑

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