Skip to content

[AGP 9] Add to app agp9 host error - #193888

Open
jesswrd wants to merge 5 commits into
flutter:masterfrom
jesswrd:add-to-app-agp9-host-error
Open

jesswrd wants to merge 5 commits into
flutter:masterfrom
jesswrd:add-to-app-agp9-host-error

Conversation

@jesswrd

@jesswrd jesswrd commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Adds an error message to add the built-in kotlin and newDsl opt-out flags for add-to-app scenarios to the host app's gradle.properties file. The Flutter migrator cannot write to android host apps.

Fixes #193682
Related to #181557

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.

… warning

detectApplyingKotlinGradlePlugin printed the name and build file of the project the
Flutter Gradle Plugin is applied to. In add-to-app builds that's the Flutter module's
:flutter project at .android/Flutter/build.gradle, not the host subproject that
actually applies KGP, so the warning pointed at the wrong project and file.

Record the app subproject's own name and build file inside the subprojects loop
and report those instead. Normal Flutter apps are unaffected because the plugin
project and the app subproject are the same project there.
…tlin opt-outs

Add FlutterPluginUtils.checkAddToAppHostAgp9Config, which fails with an actionable
GradleException when an add-to-app host built with AGP 9+ either hasn't opted out
of android.newDsl, or has built-in Kotlin enabled while the host app or a Flutter
plugin still applies the Kotlin Gradle Plugin (KGP).

The check only runs for the Flutter module library project inside a native host
build. It skips normal Flutter apps (handled by the Flutter tool migrators),
flutter build aar, and AGP versions below 9. The error names the missing flag(s),
the absolute host gradle.properties path, and a docs link.

The build-script scan for KGP only decides whether the built-in Kotlin section is
shown, so hosts that have fully migrated to built-in Kotlin aren't forced to opt
out. The error doesn't list the projects that apply KGP: once the developer adds
android.builtInKotlin=false, the next build succeeds and
detectApplyingKotlinGradlePlugin warns about each of them.

This commit only adds the check and its unit tests. It isn't called yet.

Part of flutter#193682
Call checkAddToAppHostAgp9Config before anything that can touch old AGP DSL types.
If it ran any later, an add-to-app host on AGP 9 without android.newDsl=false would
fail first with an unexplained NullPointerException instead of the actionable error.

Add a FlutterPluginTest that applies the plugin to an AGP 9 add-to-app module project
with no opt-outs and asserts the error is thrown before the Android extension is used.

Fixes flutter#193682
…st_app_with_module_source

Before the existing host app builds, check two failing configurations end to end:

- Remove android.newDsl=false from the host gradle.properties and expect the
  newDsl-only error.
- Declare the Kotlin Gradle Plugin in the host app and expect the built-in
  Kotlin-only error that asks for android.builtInKotlin=false.

Each case restores the file it changed. The existing debug and release builds that
follow verify that the opted-out host, which is migrated to built-in Kotlin, still
builds without the error.

Part of flutter#193682
@jesswrd
jesswrd requested a review from a team as a code owner October 6, 2026 05:34
@jesswrd
jesswrd requested review from reidbaker and removed request for a team October 6, 2026 05:34
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Oct 6, 2026
@jesswrd
jesswrd removed the request for review from reidbaker October 6, 2026 05:34
@github-actions github-actions Bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. labels Oct 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces validation checks for add-to-app Android host apps using Android Gradle Plugin (AGP) 9+ to ensure compatibility with the included Flutter module. Specifically, it fails the build with actionable instructions if the host app has not opted out of android.newDsl or if built-in Kotlin is enabled while the Kotlin Gradle Plugin (KGP) is still applied. Additionally, it updates KGP detection to log the specific subproject path and adds corresponding integration and unit tests. Feedback suggests using allprojects instead of subprojects when checking for KGP application to ensure the root project itself is also evaluated.

// opts out, detectApplyingKotlinGradlePlugin warns about each of them.
val kgpStillApplied =
isBuiltInKotlinEnabled(project, agpVersion) &&
project.rootProject.subprojects.any { getSubprojectPluginState(it)?.hasKgpPlugin == true }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using allprojects instead of subprojects ensures that if the root project itself applies the Kotlin Gradle Plugin (KGP) (which can happen in some custom or non-standard Gradle project structures), it will be correctly detected.

Suggested change
project.rootProject.subprojects.any { getSubprojectPluginState(it)?.hasKgpPlugin == true }
project.rootProject.allprojects.any { getSubprojectPluginState(it)?.hasKgpPlugin == true }

@reidbaker-agent

Copy link
Copy Markdown
Contributor

Heads up on the newDslNotOptedOut half of checkAddToAppHostAgp9Config (and the TODO(jesswon) at FlutterPluginUtils.kt:99):

Since this PR was opened, #193693 and #193717 landed on master (and are on flutter-3.50-candidate.0), migrating the Flutter Gradle Plugin's app and add-to-app module paths onto the public AGP Variant API. Add-to-app source builds now work with android.newDsl=true as long as built-in Kotlin is enabled and neither the host app nor any plugin applies kotlin-android or uses legacy variant APIs.

If newDslNotOptedOut lands as a standalone error condition here, it will block migrated add-to-app host apps on AGP 9+ from using android.newDsl=true. Could we:

  1. Remove newDslNotOptedOut as a standalone failure trigger (and drop/invert the first new section in build_android_host_app_with_module_source.dart so a migrated host without android.newDsl=false is allowed to build)?
  2. Keep the kgpStillApplied check (and the appApplyingKgp fix in detectApplyingKotlinGradlePlugin), and in the kgpStillApplied message instruct the user to add both android.builtInKotlin=false and android.newDsl=false when opting out—since org.jetbrains.kotlin.android itself refuses to apply if android.newDsl remains at AGP 9's true default?

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AGP 9] Add Helpful Error Message For Add-to-app

2 participants