目标
Flutter工程作为module打包成AAR,上传至Nexus(或其他maven center),供其他Native壳工程使用。
实现
使用的是 Flutter (Channel stable, v1.2.1),其他版本的没有试过。
直接
cd .android
./gradlew Flutter:assembleRelease
可以打出的AAR,但是被壳工程调用会crash。
发现少文件:
isolate_snapshot_data
isolate_snapshot_instr
vm_snapshot_data
vm_snapshot_instr
flutter_assets/*
使用
flutter build apk
打出来的apk里有,解包拿文件不太悠雅。
他是怎么打进去的呢?得看 flutter/packages/flutter_tools/gradle的过程
但是别忘了这个
flutter build -h
Flutter build commands.
Usage: flutter build <subcommand> [arguments]
-h, --help Print this usage information.
Available subcommands:
aot Build an ahead-of-time compiled snapshot of your app's Dart code.
apk Build an Android APK file from your app.
appbundle Build an Android App Bundle file from your app.
bundle Build the Flutter assets directory from your app.
flx Deprecated
ios Build an iOS application bundle (Mac OS X host only).
尝试了一下
flutter build aot
flutter build bundle --precompiled
build/aot/isolate_snapshot_data
build/aot/isolate_snapshot_instr
build/aot/vm_snapshot_data
build/aot/vm_snapshot_instr
build/flutter_assets/*
这正是想要的!
cp到assets里打包,不crash可用。
完全可行。
剩下的就是稍微整合一下了。
shell实现了,当然也可以写groovy,加到.android/Flutter/build.gradle 的后面。