之前搞的Flutter版工具链已经弄完了,感兴趣的朋友可以围观下,Android版本dio库(v2.0.14)发送网络请求老是报错,去官方提了issue还没回,于是今天搞一下把Flutter模块接入到已有项目中。
首先Flutter官方已经出了wiki,教大家怎么接入。懒得看官方原文的可以看看这个简易版快速集成,先来看看效果。
一、创建Flutter模块
一般用Flutter
或者React Native
的团队大部分原因都是因为需要跨平台,所以在已有项目目录的上一级创建Flutter
模块,譬如你的工作目录在some/path/MyApp
,那么你需要在some/path
下执行,这样Flutter
可以单独交给一个虚拟团队维护,各自独立。
$ cd some/path/
$ flutter create -t module my_flutter
文件结构如下:
some/path/
my_flutter/
lib/main.dart
.ios/
MyApp/
MyApp.xcodeproj
Podfile
MyApp/
AppDelegate.h
AppDelegate.m (or swift)
二、利用Cocoapods添加依赖
没用过Cocoapods
的童鞋可以google
搜一下,之前写过很多Cocoapods
的文章由于博客主机商跑路都没了,说多了都是泪
1.在Podfile文件加入以下代码:
flutter_application_path = '../my_flutter/'
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
注意my_flutter
的路径,因为我们是以xcodeproj
文件的上一级创建的,所以需要加../,这个和React Native
引入依赖路径是一样的,都需要注意这个问题。
2.执行pod install
注:如果报错
[!] InvalidPodfilefile: No such file or directory @ rb_sysopen - ./my_flutter/.ios/Flutter/podhelper.rb.
需要在