Skip to content

fix(pdfx): AGP-aware built-in Kotlin detection, silent KGP fallback - #657

Open
MilanJa wants to merge 1 commit into
ScerIO:mainfrom
MilanJa:fix/pdfx-agp9-built-in-kotlin
Open

MilanJa wants to merge 1 commit into
ScerIO:mainfrom
MilanJa:fix/pdfx-agp9-built-in-kotlin

Conversation

@MilanJa

@MilanJa MilanJa commented Nov 12, 2026

Copy link
Copy Markdown

What

Follow-up to #624 (pdfx 2.10.0, "Supported AGP 9 built-in Kotlin"). Three gaps remain in packages/pdfx/android/build.gradle:

  1. Wrong default on AGP 9. The guard defaults android.builtInKotlin 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 kotlin-android applied and fails with
    The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0.
    
    Only apps that explicitly write android.builtInKotlin=true (or false, taking the KGP path) build today.
  2. Flutter still warns. Flutter's "plugins that apply Kotlin Gradle Plugin (KGP)" check is a text match on apply plugin: 'kotlin-android', so pdfx is listed even when the guard skips the line. Flutter has said this guarded form will stop building once that check is tightened ([AGP 9] KGP warning lists already-migrated plugins: detectApplyingKotlinGradlePlugin regex-matches guarded 'apply plugin: kotlin-android' lines flutter/flutter#189770).
  3. No jvmTarget on the built-in path. kotlinOptions is skipped in built-in mode but nothing sets the Kotlin target there, while compileOptions is Java 11.

Fixes #615.

How

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) {
    pluginManager.apply('kotlin-android')
}
  • Built-in Kotlin only exists on AGP 9+; there it is on unless the app opts out with an explicit false. The property is checked for presence, not truthiness, so false is honoured and the AGP 8 behaviour is unchanged whatever the property says.
  • pluginManager.apply(...) keeps Flutter's text check from flagging the plugin.
  • kotlinOptions { jvmTarget = '11' } stays on the KGP path; kotlin { compilerOptions { jvmTarget = JVM_11 } } is added for the built-in path.
  • No Dart, native or pubspec changes. Minimum Flutter version unchanged.

Truth table (Gradle 9.3.1 / Groovy 4.0.29, AGP major injected)

AGP android.builtInKotlin builtIn apply KGP kotlinOptions compilerOptions
8 unset false yes yes no
8 true false yes yes no
8 false false yes yes no
9 unset true no no yes
9 true true no no yes
9 false false yes yes no

(Row 4 is the case that fails on 2.11.0.)

Real builds (Flutter 3.47.9)

Path Project Result
AGP 9.1.1, Gradle 9.3.1, builtInKotlin=true packages/pdfx/example (AGP/KGP/Gradle bumped locally, kotlin-android removed from the app module) BUILD SUCCESSFUL, :pdfx:compileDebugKotlin ran, no KGP warning
AGP 9.1.1, Gradle 9.3.1, builtInKotlin=false a production app with ~40 plugins, this branch via dependency_overrides APK built; pdfx no longer in Flutter's "plugins that apply KGP" list
AGP 8.5.2, KGP 1.9.23 (example as published) packages/pdfx/example BUILD SUCCESSFUL, :pdfx:compileDebugKotlin ran, no KGP warning. Needed --android-skip-build-dependency-validation, Gradle 8.14.3 and a 4 GB heap only because Flutter 3.47 rejects the example's AGP 8.5.2 / Gradle 8.10.2 and its 1.5 GB jvmargs is too small for Jetifier; none of that is related to this change

The example app is left untouched here; it will need the AGP/Gradle bumps above when it moves to AGP 9.

🤖 Generated with Claude Code

…P fallback silent

pdfx 2.10.0 (ScerIO#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 ScerIO#615.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant