.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