Skip to content

fix(android): support AGP 9 built-in Kotlin - #986

Open
goaly-ai-bot wants to merge 1 commit into
zeshuaro:mainfrom
goaly-ai-bot:agp9-built-in-kotlin
Open

fix(android): support AGP 9 built-in Kotlin#986
goaly-ai-bot wants to merge 1 commit into
zeshuaro:mainfrom
goaly-ai-bot:agp9-built-in-kotlin

Conversation

@goaly-ai-bot

Copy link
Copy Markdown

Problem

Android Gradle Plugin 9 ships Kotlin support built in and fails the build when a module applies the Kotlin Gradle Plugin on top of it. Any app on AGP 9 that depends on google_api_headers (directly or transitively) cannot build:

A problem occurred evaluating project ':google_api_headers'.
> Failed to apply plugin 'kotlin-android'.
   > ⛔ Failed to apply plugin 'org.jetbrains.kotlin.android'
     The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin
     support since AGP 9.0.

AGP 9 also removed android.kotlinOptions.

I hit this in an app that reaches google_api_headers transitively through a place-picker package, where it was the last remaining blocker for the AGP 9 upgrade.

Change

android/build.gradle, compatible with both AGP 8 and AGP 9:

  • kotlin-android is applied only when AGP is older than 9, using the same guard the already-migrated plugins use (device_info_plus, share_plus, package_info_plus, wakelock_plus):

    def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
    if (agpMajor < 9) {
        apply plugin: "kotlin-android"
    }
  • kotlinOptions { jvmTarget } moves into kotlin { compilerOptions { jvmTarget } }.

No version bumps, no Dart or Kotlin source changes, no behavior change.

Verified

With this patch applied through a path override in a Flutter 3.47.2 app:

Toolchain Result
AGP 8.12.2 / Gradle 8.14.3 flutter build apk --debug OK
AGP 9.0.1 / Gradle 9.1.0 / android.builtInKotlin=true flutter build apk --debug OK, flutter build appbundle --release OK

Reference: Built-in Kotlin migration for plugin authors

Happy to adjust style or split it however you prefer.

🤖 Generated with Claude Code

https://claude.ai/code/session_018VxBdp58Dd1HeCZgwFiwkD

AGP 9 removed android.kotlinOptions and fails the build when the Kotlin
Gradle Plugin is applied on top of its built-in Kotlin support. Apply the
plugin only for AGP 8 and move jvmTarget into the kotlin{} block, which
both toolchains understand.
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.

2 participants