iOS原生项目与flutter混编

新建一个项目iOSMixFlutter


image.png
@property (strong, nonatomic) UIWindow *window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    
    self.window.rootViewController = [[ViewController alloc] init];
    [self.window makeKeyAndVisible];
    
    return YES;
}

运行界面为


image.png

用cocopod初始化,步骤为
https://www.jianshu.com/p/c3e20ec5cf9d

image.png

执行

清除flutter缓存
rm /Applications/flutter/bin/cache/lockfile 
让配置生效
source ~/.bash_profile
进入相关文件
cd /Users/yyz/Desktop/flutterMix/iOSMixFlutter
生成flutter的module
flutter create --template module my_flutter

执行结束如下图


image.png

修改Podfile文件

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

  install_all_flutter_pods(flutter_application_path)
image.png

执行pod install


image.png

运行项目点击跳转成功


image.png
image.png

写第一个demo的时候 ,运行失败了,flutter的路径除了问题,加了脚本,OK了!


image.png

flutter sdk的路径

"/Applications/flutter/packages/flutter_tools/bin/xcode_backend.sh" build
"/Applications/flutter/packages/flutter_tools/bin/xcode_backend.sh" embed

网上查的相对路径,不好使,所以填了绝对路径

"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed

你可能感兴趣的:(iOS原生项目与flutter混编)