Skip to content

DID-10137: [FIX-FLUTTER-KGP] Android: support AGP 9 built-in Kotlin (apply KGP only when built-in Kotlin is off) - #35

Merged
arosasg merged 3 commits into
mainfrom
botinc/run-5f3632ec
Nov 7, 2026
Merged

arosasg merged 3 commits into
mainfrom
botinc/run-5f3632ec

Conversation

@botinc-agent

@botinc-agent botinc-agent Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Refs #28

Problem

didit_sdk always applies the Kotlin Gradle Plugin (KGP). android/build.gradle.kts declares id("kotlin-android") in plugins { } and sets the JVM target through android { kotlinOptions }, which only exists when KGP is applied. AGP 9 compiles Kotlin itself ("built-in Kotlin") and refuses projects that also apply KGP. Flutter 3.47 scans each plugin's plugins { } block for KGP and, on AGP 9, prints WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): didit_sdk, adding that future versions will fail such builds. The generated variant packages carry the same script.

Solution

  • Drop kotlin-android from plugins { }. Apply it only when built-in Kotlin is off (AGP below 9, or android.builtInKotlin=false), which is the rule Flutter's own Gradle plugin uses. AGP 8 apps and older Flutter versions keep compiling the plugin.
  • Set JVM target 17 through kotlin { compilerOptions }, which exists with both KGP and built-in Kotlin. This needs KGP 2.0+, which the native SDK's Kotlin 2.1 metadata already requires.
  • Declare kotlin-test-junit5 and junit-platform-launcher for the unit tests. KGP used to infer them; built-in Kotlin does not, so kotlin.test.Test did not resolve.
  • Regenerate the variant packages with tool/generate_variant_packages.sh. The generator needs no change.
  • Move the example app to the Flutter 3.47 template shape: no kotlin-android, and a kotlin { compilerOptions } block.
  • Add a CI job, "Example app builds (Android, AGP 9 built-in Kotlin)". It moves the example to AGP 9.2.1, Gradle 9.5.1 and android.builtInKotlin=true, builds the APK, runs the plugin's unit tests, and fails if Flutter's KGP warning names didit_sdk. The AGP 8 job is unchanged.

Verification

Run locally with Flutter 3.47.9 and JDK 17:

Setup Result
AGP 8.11.1, Gradle 8.14 Plugin compiles; 9/9 plugin unit tests pass
AGP 9.2.1, Gradle 9.5.1, built-in Kotlin New CI job's steps replayed: debug APK builds, 9/9 tests pass, no KGP warning; classes target Java 17
AGP 9.2.1, builtInKotlin=false Plugin and app compile; no warning
main's script on AGP 9 Warning names didit_sdk (flag off), build fails (flag on), so the new job catches a regression
  • flutter analyze: no issues. flutter test: 39/39 passed.
  • Regenerated variant scripts differ from the root only in the default variant.
  • CI has not run on this head yet.

@arosasg

arosasg commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Codex review (codex CLI, account codex-5, model gpt-5.6-sol)


💡 Code review

Reviewed commit: 402d342

P1 Badge Keep the Kotlin plugin enabled for the AGP 8 example build

example/android/app/build.gradle.kts:L2-L4 - view

When the checked-in example runs with its configured AGP 8.11.1, removing org.jetbrains.kotlin.android leaves MainActivity.kt without Kotlin compilation and the later kotlin { ... } configuration without its extension; declaring the plugin with apply false in settings does not apply it to the app. Apply Kotlin conditionally for AGP 8 while omitting it only in the AGP 9 built-in-Kotlin CI variant.

Verdict: REQUEST CHANGES

Both Android example builds now fail when the APK has no MainActivity
class, which is what a build that skipped Kotlin compilation produces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@arosasg

arosasg commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Reply to the Codex review (P1, keep the Kotlin plugin for the AGP 8 example build): declined, with proof added.

On AGP 8 the Flutter Gradle Plugin applies the Kotlin Gradle Plugin to the app module itself when built-in Kotlin is off. The example's build script has a top-level kotlin { compilerOptions { ... } } block, which would not even compile without the Kotlin extension, and the AGP 8 job built app-debug.apk on 402d342.

So this is a permanent check rather than an argument: 8c47c14 makes both Android example jobs (AGP 8 and AGP 9 built-in Kotlin) fail when the APK has no MainActivity class, which is what a build that skipped Kotlin compilation would produce.

@arosasg

arosasg commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Codex review (codex CLI, account codex-2, model gpt-5.6-sol)


💡 Code review

Reviewed commit: 8c47c14

P1 Badge Apply the Kotlin plugin when the example uses AGP 8

example/android/app/build.gradle.kts:L1-L4 - view

With the repository's default AGP 8.11.1 configuration, built-in Kotlin is unavailable, but this block no longer applies org.jetbrains.kotlin.android; declaring it with apply false in settings does not compile src/main/kotlin/MainActivity.kt. Consequently the normal example APK can omit MainActivity and the newly added APK assertion will fail. Apply KGP conditionally for AGP 8 while continuing to omit it under AGP 9 built-in Kotlin.

Verdict: REQUEST CHANGES

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@arosasg

arosasg commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Reply to Codex round 2 (same P1 as round 1): declined, now proven by CI on 8c47c14.

Run 42346911071: in Example app builds (Android) (AGP 8.11.1, the repository default) the step Example APK contains the Kotlin MainActivity passed, so the AGP 8 APK contains Lme/didit/sdk/sdk_flutter_example/MainActivity;. The AGP 9 built-in Kotlin job passed the same check. With AGP 8 the Flutter Gradle Plugin applies the Kotlin Gradle Plugin itself.

The plugins block still carried the template comment about applying Flutter's plugin after the Kotlin Gradle Plugin, which read as if Kotlin were missing; the latest commit replaces it with the explanation above.

@arosasg

arosasg commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Codex review (codex CLI, account codex-5, model gpt-5.6-sol)


💡 Code review

Reviewed commit: bcabd68

No blocking findings for commit bcabd68.

Verdict: APPROVE

@arosasg
arosasg merged commit 99f4ed6 into main Nov 7, 2026
9 of 10 checks passed
@arosasg
arosasg deleted the botinc/run-5f3632ec branch November 7, 2026 10:03
@arosasg arosasg mentioned this pull request Nov 7, 2026
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.

1 participant