Flutter Module Android的构建流程
Posted Beason_H
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter Module Android的构建流程相关的知识,希望对你有一定的参考价值。
对于目前市场上的集成方式来说最常用的就是原生工程+Flutter Module实现部分业务逻辑的跨平台开发,这里我们一起来分析一下Flutter Module是如何参与到android的构建流程当中的;
首先如果对Flutter APP构建流程不熟悉的可以先熟悉:“深度了解Flutter APP的构建流程”
我们分一下几个步骤了解
- settings.gradle
- include_flutter.groovy
- module_plugin_loader.gradle
- build.gradle
对于第3,4点,与Flutter APP构建流程相似,在"深度了解Flutter APP的构建流程"文中有解析,这里不再重复,重点看前两个步骤
1. settings.gradle核心部分
//导入配置.android/include_flutter.groovy
// inculde_flutter.groovy内部会引入":flutter"
rootProject.name = 'android_generated'
setBinding(new Binding([gradle: this]))
evaluate(new File(settingsDir, 'include_flutter.groovy'))
2. include_flutter.groovy核心部分
include_flutter.groovy是创建flutter module是自动生成,一帮情况下无需手动修改
// 查找项目根路径
def scriptFile = getClass().protectionDomain.codeSource.location.toURI()
def flutterProjectRoot = new File(scriptFile).parentFile.parentFile
// 导入flutter module名称为相对当前目录的flutter
gradle.include ":flutter"
// flutter module android真正的实现位于.android/Flutter目录下
gradle.project(":flutter").projectDir = new File(flutterProjectRoot, ".android/Flutter")
// 获取 配置文件.android/local.properties
def localPropertiesFile = new File(flutterProjectRoot, ".android/local.properties")
def properties = new Properties()
assert localPropertiesFile.exists(), "❗️The Flutter module doesn't have a `$localPropertiesFile` file." +
"\\nYou must run `flutter pub get` in `$flutterProjectRoot`."
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
// 获取flutter sdk路径,导入module_plugin_loader.gradle
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
gradle.apply from: "$flutterSdkPath/packages/flutter_tools/gradle/module_plugin_loader.gradle"
到了这里,整个流程比较简单,后续的module_plugin_loader.gradle, app/build.gradle,flutter.gradle都在上一篇文中"深度了解Flutter APP的构建流程"有做分析,这里不再阐述。
以上是关于Flutter Module Android的构建流程的主要内容,如果未能解决你的问题,请参考以下文章
找不到通过 Flutter Module 构建的本地 aar
Android项目创建Flutter module后运行编译失败问题