一获茬、獲取SDK港庄,搭建環(huán)境
1、直接下載文件解壓到目標(biāo)路徑恕曲,SDK下載地址:
cd ~/Flutter
unzip ~/Downloads/flutter_macos_1.20.4-stable.zip
2鹏氧、cd到目標(biāo)路徑,然后從Github上repo分支源碼:
cd ~/Flutter
git clone https://github.com/flutter/flutter.git
3佩谣、配置 flutter 的 PATH 環(huán)境變量把还,并使之永久生效:
3.1 首先獲取 Flutter SDK 安裝目錄的路徑
3.2 打開 $HOME/.bashrc 文件,并且加入以下代碼,保存關(guān)閉
export PATH=/Users/apple/flutter/bin:$PATH //為3.1步驟獲取的路徑
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
3.3 修改 $HOME/.zshrc 文件笨篷,使每次啟動我們的Mac都自動執(zhí)行命令瞳秽,文件最后加入以下代碼
source ~/.bash_profile
3.4 運(yùn)行 source $HOME/.bash_profile 來刷新當(dāng)前命令行窗口
3.5 運(yùn)行 flutter doctor -v 命令查看環(huán)境是否需要安裝其他依賴
二、原生集成 Flutter 方案對比
Flutter module
第一步要創(chuàng)建一個 Flutter module
cd some/path/
flutter create --template module my_flutter
1率翅、通過 Cocoapods 直接集成练俐,指向上述工程
1.1 在 Podfile
中添加下面代碼:
flutter_application_path = '../my_flutter'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
1.2 每個需要集成 Flutter 的 [Podfile target][],執(zhí)行 install_all_flutter_pods(flutter_application_path)
:
target 'MyApp' do
install_all_flutter_pods(flutter_application_path)
end
1.3 運(yùn)行 pod install冕臭。
2腺晾、在 Xcode 中集成 frameworks
2.1 編譯 frameworks
flutter build ios-framework --output=some/path/MyApp/Flutter/
編譯后目錄如下:
some/path/MyApp/
└── Flutter/
├── Debug/
│ ├── Flutter.framework
│ ├── App.framework
│ ├── FlutterPluginRegistrant.framework (only if you have plugins with iOS platform code)
│ └── example_plugin.framework (each plugin is a separate framework)
├── Profile/
│ ├── Flutter.framework
│ ├── App.framework
│ ├── FlutterPluginRegistrant.framework
│ └── example_plugin.framework
└── Release/
├── Flutter.framework
├── App.framework
├── FlutterPluginRegistrant.framework
└── example_plugin.framework
2.2 拖動所需要 Framework 進(jìn)去工程
3、使用 CocoaPods 在 Xcode 和 Flutter 框架中內(nèi)嵌應(yīng)用和插件框架
3.1 除了將一個很大的 Flutter.framework 分發(fā)給其他開發(fā)者辜贵、機(jī)器或者持續(xù)集成 (CI) 系統(tǒng)之外悯蝉,你可以加入一個參數(shù) --cocoapods 將 Flutter 框架作為一個 CocoaPods 的 podspec 文件分發(fā)。這將會生成一個 Flutter.podspec 文件而不再生成 Flutter.framework 引擎文件
flutter build ios-framework --cocoapods --output=some/path/MyApp/Flutter/
3.2 上傳到我們私有庫
pod lib create KYFlutterPod
3.3 打上標(biāo)簽推到遠(yuǎn)端
3.4 pod集成
pod 'KYFlutterPod', :git => 'http://xxx.com/xxxx/xxx.git'