本篇文章大幅参考了 caijinglong 大佬的总结文章: 把flutter作为framework添加到已存在的iOS中[1]
用 Flutter 来开发,从来都不可能是新开的一个纯 Flutter 项目,很大一部分都是 老项目接入 Flutter 来混编。
在 Flutter 官网 - Adding to an iOS app[2] 这里,官方也给出了一些将 Flutter 集成进入现有 iOS 项目的方法。但是,这些都多多少少的不符合我们的需求。
1. 从 Flutter Module 说起
想要把 Flutter 集成进现有 iOS 项目,我们就必须使用 Flutter Module。
那就先用命令创建一个 Flutter Module:flutter create --template module flutter_test_module
Flutter APP 和 Flutter Module 的不同之处在于 pubspec.yaml
最后一段:
# This section identifies your Flutter project as a module meant for# embedding in a native host app. These identifiers should _not_ ordinarily# be changed after generation - they are used to ensure that the tooling can# maintain consistency when adding or modifying assets and plugins.# They also do not have any bearing on your native host application's# identifiers, which may be completely independent or the same as these.module:androidX: trueandroidPackage: com.example.flutter_test_moduleiosBundleIdentifier: com.example.flutterTestModule
这一段代码,把该 Flutter 项目标注为一个 module,用于嵌入到原生 app 里。
这里面设置了是否使用 androidx,Android 和 iOS