Flutter嵌入iOS原生工程

主要解决问题:

  • pod install 失败问题
  • pod install 成功后找不到 文件问题

将你的Flutter放在与项目同一目录下

举例

  • YourProcutRootDIR
    • FlutterProduct
      • .git
      • .gitignore
      • pubspec.lock
      • pubspec.yaml
      • other files
    • YourProduct
      • .git
      • .gitignore
      • YourProductDir
        • Podfile
        • Pods
        • Podfile.lock
        • YourProduct.xcodeproj
        • YourProduct.xcworkspace
        • other files

配置 YourProduct/YourProductDir/Podfile

在 配置 flutter_application_path = 'path'时,path格式为 "../../FlutterProduct", 其中"FlutterProduct"为你的flutter项目名称;
其他相关配置按官方指导来:
(注:设置的platform,iOS版本不能太低,否则flutter pod时会提示版本太低)
举例:
flutter_application_path = '../../FlutterProduct'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

platform :ios, '9.0'
target "YourProduct" do
use_frameworks!
install_all_flutter_pods(flutter_application_path)
end

FlutterProduct配置处理

以上例子默认已有现成的FlutterProduct,否则可通过命令行创建:

flutter create module
关键步骤:
  1. 执行 在FlutterProduct目录下执行 flutter clean命令
flutter clean
  1. 'flutter clean' 执行成功后,还在当前目录执行: flutter pub upgrade 命令
flutter pub upgrade 

这两步主要是去除 FlutterProduct里关于 cocoapod一些默认配置,这些配置会导致xcode运行项目时,找不到文件

最终的融合

回到你的 YourProduct 目录下,进入YourProductDir目录,此时 执行 ls 命令行 能看Podfile 文件.
以下示例命令行,处于你当前还处于FlutterProduct目录下的情景执行

cd ../YourProduct/YourProductDir
ls

然后执行pod install

pod install

如果失败了,请检查podfile配置.主要检查 "flutter_application_path"配置
成功后打开工程,可以运行了;

你可能感兴趣的:(Flutter嵌入iOS原生工程)