之前寫過(guò)一點(diǎn)點(diǎn)純flutter的項(xiàng)目,最近比較好奇原生跟flutter混編,于是按照官方文檔進(jìn)行配置集成flutter到現(xiàn)有工程,集成后pod install報(bào)錯(cuò),podfile中改為如下配置安裝成功
target 'flutter-test' do
end
flutter_application_path = '../my_flutter'
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
原生項(xiàng)目中跳轉(zhuǎn)flutter頁(yè)面代碼如下
- (IBAction)showFlutterOnClick:(UIButton *)sender {
UIViewController *rootViewController = [[FlutterViewController alloc] initWithProject:nil nibName:nil bundle:nil];
[self.navigationController pushViewController:rootViewController animated:YES];
}
點(diǎn)擊跳轉(zhuǎn)后可以跳轉(zhuǎn)但是報(bào)錯(cuò)如下
2020-05-09 15:18:39.443794+0800 flutter-test[14940:251135] Failed to find assets path for "Frameworks/App.framework/flutter_assets"
2020-05-09 15:18:39.510195+0800 flutter-test[14940:251300] [VERBOSE-2:engine.cc(118)] Engine run configuration was invalid.
2020-05-09 15:18:39.510379+0800 flutter-test[14940:251300] [VERBOSE-2:FlutterEngine.mm(308)] Could not launch engine with configuration.
2020-05-09 15:18:39.577726+0800 flutter-test[14940:251307] flutter: Observatory listening on http://127.0.0.1:61474/1vf_vYKqgAI=/
百度后,應(yīng)該增加如下腳本,具體配置參考Xcode 11.4 Support
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" thin
重新編譯,點(diǎn)擊跳轉(zhuǎn)后正常顯示flutter頁(yè)面