Repository navigation
FIX(android): support AGP 9 built-in Kotlin (closes #46) - #47
tetianazakhozhaeva wants to merge 2 commits into
Conversation
Apply kotlin-android only on AGP < 9 or when the app opts out of built-in Kotlin (android.builtInKotlin=false).
|
@tetianazakhozhaeva Thanks for contributing this fix! Supporting AGP 9 built-in Kotlin is important: applying Before merging, I would like to address two points:
I support merging this fix once the compatibility policy is reflected in the implementation and these Android builds are validated. This review is based on the diff, issue, workflow, and official documentation; I have not independently run the builds locally because Flutter and a Java runtime are unavailable in the review environment. |
Review follow-up on yanncabral#46. Compatibility: the top-level kotlin { compilerOptions { ... } } block ran unconditionally and required KGP 2.0+, which would have raised this library's minimum (it declares Kotlin 1.8.20 and supports Flutter >= 3.41). Drop it and restore the original kotlinOptions under the same guard as the plugin apply, so the KGP path is byte-identical to before this PR and no minimum changes. Under built-in Kotlin jvmTarget is inherited from compileOptions.targetCompatibility (verified: the compiled class is major version 55, i.e. Java 11). `agpMajor < 9 ||` is now redundant — builtInKotlin is already false below AGP 9. Apply KGP through pluginManager.apply rather than `apply plugin:`: the Flutter tool scans this file for that literal to warn consumers about plugins applying KGP and cannot see the guard, so an already-migrated plugin was still listed. Both forms apply the same plugin at the same point; with this one the warning no longer names open_settings_plus on either KGP path, and its Kotlin still compiles (classes under tmp/kotlin-classes). CI: add a validate-android job building the example for the three combinations this plugin must support (AGP 8 + KGP, AGP 9 + built-in Kotlin, AGP 9 with android.builtInKotlin=false). Each entry patches the example's AGP/KGP/Gradle versions and gradle.properties; the built-in Kotlin entry also drops kotlin-android and kotlinOptions from the example app, which is the migration a consumer app has to make as well. The AGP 8 entry uses Gradle 8.14.3 / KGP 2.2.20 rather than the example's committed 8.13 / 2.2.10: the Flutter Gradle plugin enforces those minimums, so the example does not build on current stable Flutter as-is.
3f4ccb4 to
7cb887a
Compare
|
Thanks for the careful review — both points addressed in 7cb887a. 1. KGP compatibility. Dropped the top-level I also switched to 2. Android build validation. Added a
The output directory is what confirms the guard dispatches: Two notes. |
Status
READY
Description
Closes #46.
AGP 9 enables built-in Kotlin by default, and the Kotlin Gradle Plugin refuses to be applied when it is on
("The 'org.jetbrains.kotlin.android' plugin is no longer required…"), so apps using this plugin had to keep
android.builtInKotlin=false.android/build.gradlenow:kotlin-androidonly on AGP < 9 or when the app setsandroid.builtInKotlin=false(same pattern as FlutterFire), so older setups are unaffected;
android.kotlinOptionswith a top-levelkotlin { compilerOptions { jvmTarget.set(JVM_11) } },which works with both KGP and built-in Kotlin;
main.java.srcDirs += 'src/main/kotlin'(a default source dir; adding Kotlin dirs tojavaisunsupported with built-in Kotlin).
Tested with a Flutter 3.47.2 app (AGP 9.1.0, KGP 2.4.0, Gradle 9.3.1): builds with
android.builtInKotlin=false(compiled by KGP) and=true(compiled by built-in Kotlin).Type of Change