Flutter Lib
这是一个测试将 Flutter 工程打包成 aar 的项目,单纯支持 Android,测试混合开发结合的可行性。
flutter packages get 之后,执行 flutter clean,之后在android目录下执行 ./gradlew assembleRelease
- flutter_shared 的问题已经修复,但是
--local-engine
执行下依然后问题 #21107
flutter 在打包成 aar 上比 react native 简单的原因,在于它不像 react native 那样需要 link 本地的 project
- 添加完插件如果存在原生代码,会在项目里生产一个
.flutter-plugins
会包含有插件相关的信息
之后 setting.gradle
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
///include进去
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
之后在 app 中会使用 build.gradle
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
之后在 flutter.gradle 中 include 进来。
File pluginsFile = new File(project.projectDir.parentFile.parentFile, '.flutter-plugins')
Properties plugins = readPropertiesIfExist(pluginsFile)
plugins.each { name, _ ->
def pluginProject = project.rootProject.findProject(":$name")
if (pluginProject != null) {
project.dependencies {
if (project.getConfigurations().findByName("implementation")) {
implementation pluginProject
} else {
compile pluginProject
}
}
pluginProject.afterEvaluate {
pluginProject.android.buildTypes {
profile {
initWith debug
}
}
}
pluginProject.afterEvaluate this.&addFlutterJarCompileOnlyDependency
} else {
project.logger.error("Plugin project :$name not found. Please update settings.gradle.")
}
}