0%

Flutter混编

系统要求

1.系统:macOS < 10.15,macOS 10.15 废弃了对32位的支持,导致Flutter编译时会出现bad cpu type的错误;
2.Flutter:VSCode + Flutter插件;
3.Xcode < 11;
4.Android Studio > 3.0;
5.Flutter:1.7.8 hotfix.2

代码管理

  1. Flutter代码通过独立分支管理,Flutter开发人员基于此分支进行开发;
  2. Flutter开发需要在本地配置完整的开发SDK,版本开发完成后,通过命令行分别输出Android用到的aar和iOS用到的Pod;
    Flutter代码管理

实现

Flutter工程的代码结构如下:
Flutter工程目录
output/andorid:输出给Android用的aar;
output/ios:输出给iOS用的Framework和插件代码;
Flutter.podspec:输出给iOS用的Pod定义;

核心的命令行如下:

1
2
3
4
5
6
7
8
9
10
# clean
flutter clean
flutter packages get

# ios
flutter build ios --release

# android
flutter build aot --release
flutter build bundle

iOS

已有的iOS工程改动除了使用Flutter的业务代码,核心就是如何引入Flutter生成的两个动态Framework和插件,这里就涉及到CocoaPods的动静态库混合的概念,自建Pode的.podspec如下,最后通过Pod install引入这个pod

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '0.0.1'
s.summary = 'High-performance, high-fidelity mobile apps.'
s.description = <<-DESC
Flutter代码库.
DESC
s.homepage = 'https://flutter.io'
s.license = { :type => 'MIT' }
s.author = { 'heller.chan' => 'heller.chan@vipshop.com' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'

s.source_files = 'output/Classes/**/*.{h,m}'
s.vendored_frameworks = 'output/App.framework', 'output/Flutter.framework'
end

Android

已有的Android工程直接导入上面输出的aar就可以。