Skip to content

fix(android): support AGP 9 built-in Kotlin and compile against API 35 - #82

Closed
MilanJa wants to merge 1 commit into
Survicate:masterfrom
MilanJa:fix/agp9-built-in-kotlin
Closed

MilanJa wants to merge 1 commit into
Survicate:masterfrom
MilanJa:fix/agp9-built-in-kotlin

Conversation

@MilanJa

@MilanJa MilanJa commented Nov 12, 2026

Copy link
Copy Markdown

What

Makes survicate_sdk build on Android Gradle Plugin 9 while keeping the existing Kotlin Gradle Plugin (KGP) path for AGP 8. Only android/build.gradle changes; no Dart, native or pubspec changes, and the minimum Flutter version is unchanged.

Why

AGP 9 compiles Kotlin itself ("built-in Kotlin", on by default) and fails the build when a library subproject applies KGP:

> Failed to apply plugin 'kotlin-android'.
   > The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0.
     Solution: Remove the 'org.jetbrains.kotlin.android' plugin from this project's build file: .../survicate_sdk-9.0.0/android/build.gradle

Flutter 3.47 also lists survicate_sdk in its "plugins that apply Kotlin Gradle Plugin (KGP)" warning and says future Flutter releases will stop building such plugins (https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors).

Separately, on AGP 9 the plugin fails its AAR metadata check even with built-in Kotlin disabled:

Dependency 'androidx.recyclerview:recyclerview:1.4.0' requires libraries and applications that depend on it to compile against version 35 or later of the Android APIs.
:survicate_sdk is currently compiled against android-34.

recyclerview 1.4.0 comes in through com.survicate:survicate-sdk:9.0.1.

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 android.builtInKotlin=false. The property is checked for presence, not truthiness, so that opt-out is honoured and AGP 8 behaviour is unchanged whatever the property says.
  • pluginManager.apply(...) instead of apply plugin: keeps Flutter's text-based KGP check from flagging the plugin.
  • kotlinOptions { jvmTarget = '1.8' } stays on the KGP path; kotlin { compilerOptions { jvmTarget = JVM_1_8 } } is added for the built-in path, matching compileOptions.
  • compileSdkVersion 34 → 35.

This is the same pattern used by wakelock_plus and currently proposed for image_editor (fluttercandies/flutter_image_editor#164) and pdfx (ScerIO/packages.flutter#657).

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

Real builds (Flutter 3.47.9)

Path Project Result
AGP 9.1.1, Gradle 9.3.1, builtInKotlin=true example/ (AGP/KGP/Gradle bumped locally, kotlin-android removed from the app module) BUILD SUCCESSFUL, :survicate_sdk: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; survicate_sdk no longer in Flutter's "plugins that apply KGP" list
AGP 8.7.3, KGP 2.1.0 (example as committed) example/ BUILD SUCCESSFUL, :survicate_sdk: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.7.3 / Gradle 8.9 and its 1.5 GB jvmargs is too small for Jetifier; unrelated to this change

The example app and CHANGELOG are left untouched so this fits your release flow; happy to add a changelog entry or bump the example to AGP 9 if you prefer that in the same PR.

🤖 Generated with Claude Code

AGP 9 compiles Kotlin itself (built-in Kotlin, on by default) and fails
the build when a library subproject applies the Kotlin Gradle Plugin:

  The 'org.jetbrains.kotlin.android' plugin is no longer required for
  Kotlin support since AGP 9.0.

Flutter 3.47 additionally lists survicate_sdk under "plugins that apply
Kotlin Gradle Plugin (KGP)" and warns that future releases will stop
building such plugins.

- Apply KGP only when built-in Kotlin is not in effect: on AGP 8, or on
  AGP 9+ when the app sets android.builtInKotlin=false explicitly. The
  property is checked for presence, not truthiness, so the documented
  opt-out is honoured, and the same boolean gates kotlinOptions (KGP
  path) and kotlin.compilerOptions (built-in path). Using
  pluginManager.apply(...) keeps Flutter's text-based KGP check from
  flagging the plugin.
- compileSdkVersion 34 -> 35: survicate-sdk 9.0.1 pulls in
  androidx.recyclerview 1.4.0, which requires consumers to compile
  against API 35; AGP 9 enforces this in checkReleaseAarMetadata
  ("survicate_sdk is currently compiled against android-34").

No Dart, native or pubspec changes; the minimum Flutter version is
unchanged.

Copy link
Copy Markdown
Collaborator

Thanks for the PR and the detailed investigation! We reproduced both issues, but we’ve decided to handle the fix internally, so we won’t be merging this PR.

We’ll keep support for older Flutter versions and document the remaining warning instead of working around Flutter’s detection, following the Flutter team’s guidance.

Thanks again for helping us track this down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants