Repository navigation
fix(android): support AGP 9 built-in Kotlin - #161
453zhangqiang-star wants to merge 1 commit into
Conversation
CaiJingLong
left a comment
There was a problem hiding this comment.
Changes requested: correct the built-in Kotlin mode detection before relying on the legacy fallback.
[P2] Preserve an explicit android.builtInKotlin=false — image_editor_common/android/build.gradle:30-33. Groovy's Elvis operator falls back for boolean false as well as null. With AGP 9 and the property set to false, the current expression still returns true, skips this script's KGP application, skips kotlinOptions, and selects the built-in-mode compiler configuration. This contradicts the documented opt-out and the fallback promised by this PR. Distinguish an absent property from an explicit false, and derive one AGP-aware mode value that consistently controls both plugin application and compiler configuration.
Reproduced with Groovy 3.0.22: AGP=9/property=false gives builtIn=true/applyKGP=false; AGP=8/property=true gives builtIn=true/applyKGP=true, also selecting inconsistent branches. Please cover AGP 8 legacy and AGP 9 with the flag unset, true, and false. Preserve the library's existing minimum Flutter version by keeping the older-KGP configuration path usable.
Caveat: Flutter 3.44/3.47 can auto-apply KGP to migrated plugins, which can mask the false-flag defect in a full Flutter build; I have reproduced the incorrect branch selection, not claimed an APK build failure. Validation included the full Gradle diff, the six-case Groovy truth table, and Flutter/Android migration documentation. No complete Android build was run, and this head has no CI results. Reviewed 390e87a.
CaiJingLong
left a comment
There was a problem hiding this comment.
Rechecked unchanged head 390e87a. The previous blocking mode-detection finding remains, so changes are still requested.
image_editor_common/android/build.gradle:30: Groovy's Elvis fallback treats explicit false as absent. With AGP 9 and android.builtInKotlin=false, builtInKotlinEnabled still becomes true. With AGP 8 and the property true, the plugin-application and compiler-configuration branches also disagree.
Distinguish an absent property from explicit false, then use one AGP-aware boolean consistently for plugin application, kotlinOptions, and compilerOptions. Cover AGP 8 and 9 with unset/true/false properties. The prior six-case reproduction remains applicable because this head and expression are unchanged. This review does not claim a new APK failure: Flutter's automatic KGP application can mask the branch-selection error. I have left the Gradle implementation for the author to correct.
|
I've put up the requested mode-detection fix as a PR against this branch: 453zhangqiang-star#1. It checks |
|
@CaiJingLong one question on process: if there's no response from the author within a week on merging the fix (453zhangqiang-star#1), would you like me to refile the updated change as a new PR directly against @CaiJingLong 关于流程的一个问题:如果一周内作者没有回复、没有合并修复(453zhangqiang-star#1),您是否希望我直接基于 |
What
Migrate the Android build so it supports AGP 9 built-in Kotlin, while keeping the legacy
Kotlin Gradle Plugin (KGP) path working for older AGP versions.
Why
AGP 9 enables built-in Kotlin and no longer allows library subprojects to apply the
Kotlin Gradle Plugin. Flutter documents this migration and warns about plugins that
still apply KGP; future Flutter versions will fail to build them:
This pattern has already been merged upstream in other plugins, e.g.
flutter_timezone5.1.1,wakelock_plus1.7.0+, andsign_in_with_apple8.2.0.How
agpMajor < 9 || android.builtInKotlin != true).pluginManager.apply(...)instead of theapply plugin:syntax, so Flutter's staticKGP detection (which pattern-matches build file text) does not flag the plugin.
kotlinOptionsfor the legacy path and usekotlin.compilerOptionswhen built-in Kotlinis active.
image_editor_common/android/build.gradle.No Dart or native API changes.
Testing
The change is build-configuration only and mirrors the exact structure already merged in
flutter_timezone5.1.1,wakelock_plus1.7.0+ andsign_in_with_apple8.2.0.I have not run this repo's example app build yet. If you'd like, I can run
flutter build apkfor the example on Flutter 3.47.x / AGP 9.x before you review —or feel free to trigger CI. Happy to adjust the structure if you prefer a different approach.