为了让Flutter成为工作中的一部分,决定使用module的方式引入到现有的项目中
接入文档
踩坑一:设置compileOptions 失败, 永远提示需要设置 java1.8
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
最终在编译plugin 中找到了强行设置 java 1.7 的 hard code 部分,去掉后编译成功
踩坑二:运行Flutter界面后Crash,错误提示 VM snapshot must be valid.
经过 google ,github issue 总结后得出以下结论
依赖的aar中缺失了Flutter的资源,如下图
解决方案:
cd my_flutter/.android
./gradlew assembleRelease //手动创建好含有 assets文件的aar
目测assets消失的原因是flutter build脚本的兼容性不够好
集成后话
最终在官方接入的指导下,放弃了文件工程接入方式 (笑)
//删除 build.gradle中的
implementation project(':flutter')
//删除 setting.gradle中的
setBinding(new Binding([gradle: this])) // new
evaluate(new File( // new
settingsDir.parentFile, // new
'my_flutter/.android/include_flutter.groovy' // new
)) // new
把打包的flutter module aar上传到nexus 进行依赖
这样一来方便持续集成打包,以及最小化的对原有项目改造