Flutter module Android端集成

目标

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 的后面。

Sample

https://github.com/chirsjericho/flutter_module_sample

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容