首先 让我们的iOS项目 关联 Flutter模块,使用cocoapods关联,在podfile文件里添加如下代码:
flutter_application_path = '../flutter_module' //flutter模块的路径
load File.join(flutter_application_path,'.iOS','Flutter','podhelper.rb') //函数调用加载flutter
platform :ios, '12.0'
target 'NativeDemo' do
install_all_flutter_pods(flutter_application_path)
use_frameworks!
# Pods for NativeDemo
end
然后pod install 第一次报错:
[!] Invalid `Podfile` file: Missing `flutter_post_install(installer)` in Podfile `post_install` block.
# from /Users/zhangfan/Desktop/flutter_folder/NativeDemo/Podfile:7
# -------------------------------------------
# target 'NativeDemo' do
> install_all_flutter_pods(flutter_application_path)
# use_frameworks!
# -------------------------------------------
处理方法:
在podfile结尾添加
target 'app' do
// 用的各sdk
end
// 新增的配置
post_install do |installer|
flutter_post_install(installer) if defined?(flutter_post_install)
end
继续pod install 第二次报错:
[!] CocoaPods could not find compatible versions for pod "Flutter":
In Podfile:
Flutter (from `../flutter_module/.ios/Flutter`)
Specs satisfying the `Flutter (from `../flutter_module/.ios/Flutter`)` dependency were found, but they required a higher minimum deployment target.
处理方法:
修改原生Podfile文件里的Platform的版本号 和 flutter中iOS下Flutter.podspec文件中的ios.deployment_target 版本号一致!
flutter_application_path = '../flutter_module'
load File.join(flutter_application_path,'.iOS','Flutter','podhelper.rb')
platform :ios, '12.0'//这里的版本号!和下图中ios.deployment_target 版本号一致!
target 'NativeDemo' do
install_all_flutter_pods(flutter_application_path)
use_frameworks!
# Pods for NativeDemo
end
post_install do |installer|
flutter_post_install(installer) if defined?(flutter_post_install)
end
pod install 成功后,编译项目第三次报错 :
Sandbox: rsync.samba(30002) deny(1) file-write-create /Users/zhangfan/Library/Developer/Xcode/DerivedData/NativeDemo-csscysefpzumudflovqmzgvixwno/Build/Products/Debug-iphonesimulator/Flutter.framework
处理方法:
1.Xcode targets 里面 buildsettings 搜索 User Script Sanboxing 改为 NO
-
新版本的Xcode 15 编译报该错误 右侧[工具栏]项目的workspace 和 pod的 space 都选择为15.0 即可.
最后编译成功!!