fix(android): apply Kotlin plugin to file_picker on AGP 9

file_picker's android/build.gradle guards `apply plugin:
'org.jetbrains.kotlin.android'` behind a runtime AGP-version check that
is false on this project's AGP 9 (it assumes AGP's built-in Kotlin
support is active instead). Flutter's own FlutterPluginUtils only
scans the file's text for that apply statement to decide whether to
auto-apply Kotlin itself, so it is fooled by the same guarded line and
skips applying it too. With android.builtInKotlin=false (needed for
other plugins like audioplayers_android), no Kotlin plugin ever runs
for file_picker, so its Kotlin sources -- including FilePickerPlugin --
never compile, breaking `flutter build apk --release` with:

  cannot find symbol: class FilePickerPlugin

Force-apply org.jetbrains.kotlin.android for the file_picker subproject
once AGP's library plugin is present, and pin its Kotlin compile
jvmTarget to 17 (file_picker's own jvmTarget setup is behind the same
dead guard, so it would otherwise default to the running JDK's target
and conflict with the javac target). Verified with a full
`flutter build apk --release`.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 18:30:18 +02:00
parent 7617aa694e
commit f140d7a014

View File

@ -1,3 +1,10 @@
plugins {
// Declared with apply false so the Kotlin Gradle Plugin classes (used below to fix up
// file_picker's Kotlin compilation) are resolvable from this script, without applying the
// plugin to the root project itself. Version matches settings.gradle.kts.
id("org.jetbrains.kotlin.android") version "2.3.20" apply false
}
allprojects {
repositories {
google()
@ -19,6 +26,28 @@ subprojects {
project.evaluationDependsOn(":app")
}
// file_picker's android/build.gradle guards `apply plugin: 'org.jetbrains.kotlin.android'`
// behind a runtime AGP-version check (skipped on AGP 9+, where it assumes AGP's built-in
// Kotlin support is active). Flutter's own auto-apply logic in FlutterPluginUtils only
// scans the file's text for that apply statement -- it matches even though the guard makes
// it a no-op on this project's AGP 9, so Flutter skips applying Kotlin itself too. With
// android.builtInKotlin=false (kept for compatibility with other plugins), no Kotlin plugin
// ever gets applied to file_picker, and its Kotlin sources (including FilePickerPlugin) never
// compile. Apply it explicitly here once AGP's library plugin is in place.
subprojects {
if (name == "file_picker") {
pluginManager.withPlugin("com.android.library") {
pluginManager.apply("org.jetbrains.kotlin.android")
// file_picker's own jvmTarget = 17 setup is behind the same dead AGP9 guard, so its
// Kotlin compile tasks would otherwise default to the running JDK's target (21),
// conflicting with the javac target (17) set by its `compileOptions` block.
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
}
}
}
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}