? 对于目前市场上的集成方式来说最常用的就是原生工程+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核心部分
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
gradle.include ":flutter"
gradle.project(":flutter").projectDir = new File(flutterProjectRoot, ".android/Flutter")
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) }
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的构建流程"有做分析,这里不再阐述。
|