.flutter-plugins-dependencies 替换 .flutter-plugins。
概述
#flutter
工具将不再输出 .flutter-plugins
元数据文件,而只输出 .flutter-plugins-dependencies
。
依赖于 .flutter-plugins
存在的工具和构建脚本,例如 Gradle 配置(针对 Android 应用),需要进行更新。
背景
#2019 年,.flutter-plugins-dependencies
作为一种新的文件格式被添加,以替换 .flutter-plugins
。
所以,一个看起来像这样的文件
camera=/path/to/camera/plugin
shared_preferences=shared_preferences
被替换为像这样的文件
{
"dependencyGraph": {
"camera": {
"name": "camera",
"version": "0.10.0",
"dependencies": {
"flutter": "0.0.0"
}
},
"shared_preferences": {
"name": "shared_preferences",
"version": "2.0.15",
"dependencies": {
"flutter": "0.0.0"
}
}
},
"flutter": {
"frameworkRevision": "3a0f99d4f2",
"channel": "stable"
}
}
同时生成这两个文件是技术债务的来源,它使新的功能集复杂化,例如在发布应用中不捆绑 dev_dependency
插件。
迁移指南
#大多数 Flutter 开发者不会解析或使用此文件,但构建配置可能会,包括由旧版 flutter create --platforms android
调用生成的 settings.gradle
文件。这些旧文件可能仍然引用 .flutter-plugins
,并且必须更新到新的构建脚本。
例如
include ':app'
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
// Note explicitly reading the legacy '.flutter-plugins' file.
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
可能会升级到其等效的 settings.gradle.kts
pluginManagement {
val flutterSdkPath = run {
val properties = java.util.Properties()
file("local.properties").inputStream().use { properties.load(it) }
val flutterSdkPath = properties.getProperty("flutter.sdk")
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
flutterSdkPath
}
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
// Note the use of the flutter-plugin-loader versus reading '.flutter-plugins'
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.1.0" apply false
id("org.jetbrains.kotlin.android") version "1.8.22" apply false
}
include(":app")
有关切换到新插件 DSL 的帮助,请参阅废弃的 Flutter Gradle 插件的命令式应用方式。
要冒烟测试您的构建是否依赖 .flutter-plugins
文件,您可以使用功能标志 explicit-package-dependencies
flutter config --explicit-package-dependencies
任何可能依赖于 .flutter-plugins
文件输出的构建工具或脚本现在都将失败。
时间线
#落地版本:3.28.0-0.0.pre
稳定版本:3.32
此更改落地后的一个稳定版本,将不再生成 .flutter-plugins
。
参考资料
#相关问题
- Issue 48918,其中
.flutter-plugins
(在 2020 年)计划被废弃。
相关 PR