Skip to content

fix(android): migrate to Built-in Kotlin, stop applying KGP (#76) - #77

Merged
vietnguyentuan2019 merged 3 commits into
mainfrom
fix/issue-76-builtin-kotlin
Sep 23, 2026
Merged

vietnguyentuan2019 merged 3 commits into
mainfrom
fix/issue-76-builtin-kotlin

Conversation

@vietnguyentuan2019

Copy link
Copy Markdown
Contributor

Fixes #76.

android/build.gradle applied the Kotlin Gradle Plugin unconditionally. On AGP 9 Flutter flags the plugin with a warning, and with android.builtInKotlin=true the build fails outright with Failed to apply plugin 'kotlin-android'.

Changes

  • Plugin: removed apply plugin: "kotlin-android" and kotlinOptions, and added kotlin { compilerOptions { jvmTarget = JVM_17 } }.
  • Min Flutter is now 3.44 (was 3.27). 3.44 is the first Flutter that applies KGP to plugins itself when built-in Kotlin is off; on anything older the Kotlin sources wouldn't compile. The Dart floor is unchanged.
  • kotlin-test is now kotlin-test-junit. Without KGP nothing substitutes the JUnit variant, so kotlin.test.Test stopped resolving.
  • Robolectric is pinned to SDK 34 via robolectric.properties. AGP 9 gives library unit tests targetSdk 36, which Robolectric 4.12.2 rejects.
  • The example app is now on AGP 9.1, Gradle 9.3.1 and builtInKotlin=true, so CI builds the new path. Bumped workmanager to ^0.10.9, dropped the unused kapt and serialization plugins, and moved the CI pin in .fvmrc from 3.41.9 to 3.47.5.

Verification (local)

  • The plugin's class set (dexdump, 287 classes) is identical to 1.8.1 in these setups:
    • Flutter 3.47.5 with AGP 9, built-in Kotlin on
    • Flutter 3.47.5 with AGP 9, built-in Kotlin off
    • Flutter 3.47.5 with AGP 8 and root KGP
    • Flutter 3.44.0 with AGP 9
  • Flutter 3.44.0 with AGP 8 and root KGP: the plugin's Kotlin compiles. I only compiled it (no APK, low disk); its classes match the others apart from R classes, which come from the APK build.
  • There is no KGP warning in any of these setups.
  • ./gradlew testDebugUnitTest: 138 passed, 0 failed, the same as main's CI.
  • flutter test test/unit/: 1233 passed. Security tests: 75 passed. Analyze: 0 issues.
  • Regression guard: test/unit/issue_76_builtin_kotlin_test.dart runs Flutter's own KGP detection regex over android/build.gradle. It is red on main and green on this branch.

The iOS jobs couldn't be checked locally. This PR is mainly here so CI verifies them under the new pin.

…76)

android/build.gradle applied the Kotlin Gradle Plugin unconditionally. On
AGP 9, Flutter flags the plugin with a warning. With
android.builtInKotlin=true, the build fails with "Failed to apply plugin
'kotlin-android'". Future Flutter versions make that failure unconditional.

- Drop `apply plugin: "kotlin-android"` and `kotlinOptions`, and add
  kotlin.compilerOptions (jvmTarget 17).
- Raise the Flutter floor from 3.27 to 3.44. That is the first Flutter that
  applies KGP to plugins itself; below it the Kotlin would not compile. The
  Dart floor is unchanged, because bumping it changes the formatter language
  version and would reformat 125 files.
- Change kotlin-test to kotlin-test-junit. Without KGP, kotlin.test.Test no
  longer resolves.
- Pin Robolectric to SDK 34. AGP 9 gives library tests targetSdk 36, which
  4.12.2 rejects.
- Move the example to AGP 9.1, Gradle 9.3.1 and builtInKotlin=true so CI
  covers the new path. Bump workmanager to ^0.10.9 and drop the unused
  kapt/serialization plugins.
- CI pin (.fvmrc) goes from 3.41.9 to 3.47.5.

The plugin's Kotlin class set is identical to 1.8.1 in these setups:
- 3.47.5 on AGP 9, built-in Kotlin on and off
- 3.47.5 on AGP 8 with root KGP
- 3.44.0 on AGP 9 and on AGP 8

Guarded by test/unit/issue_76_builtin_kotlin_test.dart, which runs
Flutter's detection regex over android/build.gradle.
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.

Plugin applies Kotlin Gradle Plugin unconditionally — blocks Flutter's Built-in Kotlin migration

1 participant