日本語の晴見

日本語は学べば学ぶほど面白い

Flutter 升級到 AGP 8.1

Sam Xiao's Avatar 2025-01-30

使用 Android SDK Build-Tools 36-rc4 後,必須配套使用 Android SDK 35 與 Android Gradle Plugin 8.1,原來的專案需修改 settings.gradlegradle-wrapper.properties 支援 AGP 8.1

Version

Android SDK Build-Tools 36-rc4
Android SDK 35
Android Gradle Plugin 8.1
Flutter 3.27.3

AGP

android/settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

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.7.10" apply false
}

include ":app"

Line 21

id "com.android.application" version "8.1.0" apply false
  • com.android.application:設定為 8.1.0

android/gradle/wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip

Line 5

distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip
  • distributionUrl:設定為 gradle-8.1-all.zip