.flutter-plugins-dependencies
取代 .flutter-plugins
。
摘要
#flutter
工具將不再輸出舊版的 .flutter-plugins
元數據檔案,而只輸出 .flutter-plugins-dependencies
。依賴 .flutter-plugins
存在的工具和建置腳本,例如 Gradle 設定(用於 Android 應用程式),將需要更新。
背景
#在 2019 年,.flutter-plugins-dependencies
被新增為較新的檔案格式,以取代 .flutter-plugins
。
因此,一個看起來像這樣的檔案
# This is .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")
請參閱已棄用 Flutter Gradle 外掛程式的命令式套用,以了解切換到較新的外掛程式 DSL 的詳細資訊。
為了測試您的建置是否依賴 .flutter-plugins
檔案,您可以使用功能標誌 explicit-package-dependencies
flutter config explicit-package-dependencies
任何可能依賴該檔案輸出的建置工具或腳本現在都會失敗。
時間軸
#尚未發布
尚未發布 + 1,.flutter-plugins
支援將被移除。
參考資料
#相關問題
- Issue 48918,其中
.flutter-plugins
在 (2020 年) 被預定要棄用。
相關 PR
除非另有說明,否則本網站上的文件反映了 Flutter 的最新穩定版本。頁面上次更新於 2024-11-18。 檢視原始碼 或 回報問題。