iOS 集成Flutter

1、第一步:

在iOS项目的同级目录下创建flutter工程

flutter create -t module flutter_library


 

2、第二步:

cd  flutter_library

flutter build ios —debug --no-codesign

flutter build ios --release --no-codesign

等待编译完成


 

 

3、第三步:

在iOS项目中添加(加粗部分

platform :ios,'9.0'

flutter_application_path ='../flutter_library/'  #相对目录

load File.join(flutter_application_path,'.ios','Flutter','podhelper.rb')

target 'FlutteriOS' do

  use_frameworks!

  install_all_flutter_pods(flutter_application_path)

  # Pods for FlutteriOS

end

post_install do |installer|

  flutter_post_install(installer) if defined?(flutter_post_install)

  installer.pods_project.targets.each do |target|

然后pod install

 


 

这时候基本完成了配置,具体就是iOS怎么调用flutter的项目

4、第四步:

#import 

@interface AppDelegate : FlutterAppDelegate <UIApplicationDelegate>

@property (nonatomic,strong) FlutterEngine *flutterEngine;

@end

2、

#import<FlutterPluginRegistrant/GeneratedPluginRegistrant.h>// 如果你需要用到Flutter插件时

 

- (BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

    self.flutterEngine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil];

       [self.flutterEngine runWithEntrypoint:nil];

       [GeneratedPluginRegistrant registerWithRegistry:self.flutterEngine]; //如果你需要用到Flutter插件时

    return YES;

}

5、第五步:

FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithProject:nil nibName:nil bundle:nil];

        flutterViewController.navigationItem.title=@"Flutter Demo";

        [self presentViewController:flutterViewController animated:YES completion:nil];

具体图如下:

 


 

 

 

备注:

如果报错:

dyld: Library not loaded: @rpath/App.framework/App.....

解决方案:

1、卸载cocoapods

sudo gem uninstall -n /usr/local/bin cocoapods cocoapods-core cocoapods-deintegrate cocoapods-downloader cocoapods-plugins cocoapods-search cocoapods-stats cocoapods-trunk cocoapods-try

2、卸载 ruby-macho

sudo gem uninstall ruby-macho

3、重新安装pod

sudo gem install -n /usr/local/bin cocoapods

4、cd到iOS项目目录下删除原有的pods、Podfile.lock、.xcworkspace,重新pod install

posted @   黄志武(kaven)  阅读(244)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示