Skip to content

[flutter_tools] Say whether the app or a plugin applies kotlin-android under built-in Kotlin - #195081

Draft
reidbaker-agent wants to merge 2 commits into
flutter:masterfrom
reidbaker-agent:tool-kgp-builtin-kotlin-error
Draft

reidbaker-agent wants to merge 2 commits into
flutter:masterfrom
reidbaker-agent:tool-kgp-builtin-kotlin-error

Conversation

@reidbaker-agent

Copy link
Copy Markdown
Contributor

When android.builtInKotlin=true and a build file still applies kotlin-android, Flutter's message said "Starting AGP 9+, the default has become built-in Kotlin". It did not say whether the app or a plugin had to change.

The message now names the build file. For the app, it lists the migration steps. For a plugin, it says to upgrade or report the plugin, and how to build until then.

Related to #189235 and #181557.

Agent authored details

applyingKotlinAndroidPluginErrorHandler now matches the Kotlin Gradle Plugin line Solution: Remove the 'org.jetbrains.kotlin.android' plugin from this project's build file: <path>. and reads the path. Before, it matched the line above it. The path is relative to the Android root project, with the platform separator, so Windows separators are normalized. app/build.gradle(.kts) gets the app message; any other path gets the plugin message.

The escape hatch in the plugin message needs both properties: with builtInKotlin=false and newDsl=true, the Kotlin Gradle Plugin still refuses to apply.

Real output, AGP 9.3.1 and KGP 2.4.20, app applying kotlin-android:

│ [!] android/app/build.gradle.kts applies the kotlin-android plugin, which does not work with     │
│ `android.builtInKotlin=true`.                                                                    │
│ To fix this, migrate the app to built-in Kotlin:                                                 │
│   1. Remove the kotlin-android plugin (`org.jetbrains.kotlin.android`) from the plugins block of │
│   android/app/build.gradle.kts.                                                                  │
│   2. Replace any `kotlinOptions {}` block with `kotlin { compilerOptions {} }`.                  │

A plugin applying kotlin-android:

│ [!] A plugin applies the kotlin-android plugin, which does not work with                        │
│ `android.builtInKotlin=true`.                                                                   │
│ Build file: ../../plug/android/build.gradle.kts                                                 │
│ To fix this, upgrade the plugin to a version that supports built-in Kotlin.                     │
│ If no such version exists, report it to the plugin author.                                      │
│ To build until then, set `android.builtInKotlin=false` and `android.newDsl=false` in            │
│ android/gradle.properties.                                                                      │

Removed test: Failure to apply kotlin-android plugin. It asserted the old message text. It is replaced by the kotlin-android plugin with built-in Kotlin group, which covers the matcher, the app message, a Windows path and the plugin message.

Added constant kMigrateAppToBuiltInKotlinDocsUrl. The page exists, covers kotlinOptions → compilerOptions, and has the section on reporting plugins.

A cherry-pick to flutter-3.50-candidate.0 needs a small backport: gradle_errors.dart was refactored on master after the branch point (#193649).

Verification: flutter test test/general.shard/android/gradle_errors_test.dart passed (61 tests). dart analyze --fatal-infos and dart format passed on the changed files. Manual builds were run for both cases.

Known limits: in add-to-app hosts, or for an app module not named app, the wording is less precise (plugin branch, or an android/ prefix). The exit status is unchanged.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

…d under built-in Kotlin

applyingKotlinAndroidPluginErrorHandler now matches the Kotlin Gradle Plugin
line that names the offending build file. For the app module it lists the
migration steps. For a plugin it says to upgrade or report the plugin and
how to build until then.
@reidbaker reidbaker added the CICD Run CI/CD label Oct 22, 2026
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team labels Oct 22, 2026
@reidbaker
reidbaker requested a review from jesswrd October 22, 2026 23:38
@reidbaker

Copy link
Copy Markdown
Member

@jesswrd I have not reviewed this yet but wanted you to know it existed.

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

Labels

CICD Run CI/CD team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants