.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