From 04dc846a91237b67cb02dac95371b84958b8b04d Mon Sep 17 00:00:00 2001 From: Milan Jansen Date: Thu, 12 Nov 2026 14:54:43 +0100 Subject: [PATCH] fix(pdfx): make AGP 9 built-in Kotlin detection AGP-aware and keep KGP fallback silent pdfx 2.10.0 (#624) guards the Kotlin Gradle Plugin on `android.builtInKotlin`, but defaults to `false` when the property is unset. On AGP 9 built-in Kotlin is on by default, so an app that never sets the property still gets KGP applied and the build fails with "The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0". The textual `apply plugin: 'kotlin-android'` also trips Flutter's static KGP check, so pdfx shows up in the "plugins that apply KGP" warning even when the guard skips it. - Derive the mode from the AGP major: built-in Kotlin only exists on AGP 9+, where it is on unless `android.builtInKotlin=false` is set explicitly. The property is checked for presence, not truthiness. - Apply KGP through `pluginManager.apply(...)` so Flutter's text match does not flag the plugin. - Set `jvmTarget` for the built-in path through `kotlin.compilerOptions` (the KGP path keeps `kotlinOptions`), so both paths target Java 11 like `compileOptions`. Closes #615. --- packages/pdfx/android/build.gradle | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/pdfx/android/build.gradle b/packages/pdfx/android/build.gradle index d799a6f7..78fe8548 100644 --- a/packages/pdfx/android/build.gradle +++ b/packages/pdfx/android/build.gradle @@ -21,15 +21,24 @@ rootProject.allprojects { } } -// AGP 9 can run with or without built-in Kotlin, so inspect the consuming -// app's explicit setting instead of inferring the mode from the AGP version. -def builtInKotlinEnabled = (project.findProperty('android.builtInKotlin') ?: 'false') - .toString() - .toBoolean() +// AGP 9 compiles Kotlin itself (built-in Kotlin) and fails the build when a +// library subproject applies the Kotlin Gradle Plugin (KGP). Built-in Kotlin is +// on by default on AGP 9+ and can be opted out of with `android.builtInKotlin=false` +// in the consuming app's gradle.properties; on AGP 8 the property has no effect. +// An explicit `false` must be honoured, so the property is checked for presence +// rather than truthiness (Groovy's `?:` would treat `false` as absent), and the +// one resulting boolean drives plugin application and compiler configuration. +// The pluginManager form keeps Flutter's static KGP detection (a text match on +// `apply plugin: 'kotlin-android'`) from flagging this plugin. See +// https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors +def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int +def builtInKotlinProperty = project.findProperty('android.builtInKotlin') +def builtInKotlinEnabled = agpMajor >= 9 && + (builtInKotlinProperty == null || builtInKotlinProperty.toString().toBoolean()) apply plugin: 'com.android.library' if (!builtInKotlinEnabled) { - apply plugin: 'kotlin-android' + pluginManager.apply('kotlin-android') } android { @@ -60,6 +69,14 @@ android { } } +if (builtInKotlinEnabled) { + kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 + } + } +} + dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")