参考文章:
官方文档:Add-Flutter-to-existing-apps
iOS和Flutter混编系列一:如何在已有的iOS工程中添加Flutter工程
如何在现有的iOS工程中接入Flutter
原生App项目集成flutter混合开发详细指南
截止:2019-08-20
iOS
1、切换Flutter环境到master环境
查看当前环境:flutter channel
切换到master环境:flutter channel master
执行flutter doctor
2、创建项目基本目录flutter_test
3、flutter_test下使用Xcode创建iOS项目,添加CocosPods支持
4、flutter_test目录下,创建flutter module
flutter create -t module my_flutter
5、添加Flutter app到Podfile
修改Podfile文件,如下,执行pod install
:
platform :ios, '9.0'
use_frameworks!
target 'DouDiZhu' do
flutter_application_path = '../flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
install_all_flutter_pods(flutter_application_path)
end
podhelper.rb说明:
Whenever you change the Flutter plugin dependencies in some/path/my_flutter/pubspec.yaml, you need to run flutter packages get from some/path/my_flutter to refresh the list of plugins read by the podhelper.rb script. Then run pod install again from some/path/MyApp.
6、iOS项目中Build Settings->Build Options->Enable Bitcode
的bitcode改为NO
7、iOS项目中创建AppViewController.swift
,内容如下:
import UIKit
import Flutter
class AppViewController: FlutterViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
8、iOS项目中Appdelegate.swift中修改如下:
import UIKit
import Flutter
import FlutterPluginRegistrant
@UIApplicationMain
class AppDelegate: FlutterAppDelegate {
var flutterEngine: FlutterEngine?
var myWindow: UIWindow!
var navigationController: UINavigationController?
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
self.flutterEngine = FlutterEngine(name: "io.flutter", project: nil)
self.flutterEngine?.run(withEntrypoint: nil)
GeneratedPluginRegistrant.register(with: self.flutterEngine)
let appController = AppViewController()
self.navigationController = UINavigationController(rootViewController: appController)
self.myWindow = UIWindow(frame: UIScreen.main.bounds)
self.myWindow.rootViewController = self.navigationController
self.myWindow.makeKeyAndVisible()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
8、iOS项目中general中Main Interface删除为空
9、Android Studio打开flutter项目,运行到iOS设备或者模拟器一次
10、打开Xcode运行iOS项目,即可看到项目内容为flutter所开发的内容
WX20190820-195636@2x.png
网友评论