build(android): move to Flutter 3.47 template toolchain (Gradle 9.3.1 / AGP 9.1.0 / Kotlin 2.4.0)

The project pinned Gradle 8.12 / AGP 8.9.1 / Kotlin 2.1.0, all three below the
hard error floors that Flutter 3.47.1 enforces in DependencyVersionChecker.kt
(8.14.0 / 8.11.1 / 2.2.20). Nothing here had rotted; the SDK moved.

Targets Flutter's own template defaults rather than the lowest combo that
clears the floors, because Flutter promotes its warn floor to the error floor
in the very next release -- clearing only the hard floor buys one release of
runway. `flutter-android-preflight` on the host re-derives all of this from
the installed SDK.

Also:
- kotlinOptions{} -> kotlin{compilerOptions{}}: the old DSL is a script
  COMPILATION error under Kotlin >= 2.3, not a warning.
- Java/jvmTarget 11 -> 17, matching what the AndroidX artifacts now require.
- Drop android.enableJetifier (obsolete, removed outright in AGP 9); the
  Flutter migrator adds builtInKotlin/newDsl=false in its place. Keep them:
  builtInKotlin=true makes AGP 9.1.0 supply Kotlin 2.2.10, which is BELOW
  Flutter's own 2.2.20 floor, so Flutter rejects its own recommendation.
- Force plugin subprojects to compileSdk 36 / minSdk 24. bg_launcher 0.1.0 is
  abandoned at compileSdk 31 and the AndroidX artifacts it resolves to refuse
  it. The override must be registered before evaluationDependsOn(":app"),
  which evaluates subprojects eagerly. Dropping bg_launcher is the real fix.

Verified: flutter build apk --debug and --release, as both mikkeli and hermes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016dKAqFo9Uj3mPZWvDzj3G8
This commit is contained in:
2026-08-23 11:56:20 +09:00
parent a9844e9665
commit 7a58483ba2
7 changed files with 67 additions and 24 deletions
+10 -6
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
id("com.android.application")
id("kotlin-android")
@@ -11,12 +13,8 @@ android {
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
defaultConfig {
@@ -39,6 +37,12 @@ android {
}
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
flutter {
source = "../.."
}
+29
View File
@@ -15,6 +15,35 @@ subprojects {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
}
// Force plugin subprojects onto a modern compileSdk/minSdk.
// Several pinned pub plugins are stuck on ancient values -- bg_launcher 0.1.0 is
// compileSdk 31 / minSdk 16, flutter_overlay_window 0.5.0 is compileSdk 34 -- and the
// AndroidX artifacts they now resolve to refuse to be consumed by them.
// The fix belongs HERE, not in ~/.pub-cache: that cache is shared between users,
// unversioned, and invisible to git, so an edit there silently poisons every build on
// the machine and is wiped by the next `pub get`.
// Reflection is used because AGP's types are not on the root build script classpath.
// NOTE: must be registered BEFORE evaluationDependsOn(":app") below, which evaluates
// subprojects eagerly -- after it, afterEvaluate throws.
subprojects {
afterEvaluate {
val androidExt = extensions.findByName("android") ?: return@afterEvaluate
runCatching {
androidExt.javaClass
.getMethod("setCompileSdkVersion", Int::class.javaPrimitiveType)
.invoke(androidExt, 36)
}
runCatching {
val defaultConfig = androidExt.javaClass
.getMethod("getDefaultConfig")
.invoke(androidExt)
defaultConfig.javaClass
.getMethod("setMinSdkVersion", Int::class.javaPrimitiveType)
.invoke(defaultConfig, 24)
}
}
}
subprojects {
project.evaluationDependsOn(":app")
}
+4 -1
View File
@@ -1,3 +1,6 @@
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
# This builtInKotlin flag was added automatically by Flutter migrator
android.builtInKotlin=false
# This newDsl flag was added automatically by Flutter migrator
android.newDsl=false
+1 -1
View File
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip
+2 -2
View File
@@ -19,8 +19,8 @@ pluginManagement {
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.9.1" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
id("com.android.application") version "9.1.0" apply false
id("org.jetbrains.kotlin.android") version "2.4.0" apply false
}
include(":app")