Repository navigation
Conversation
… 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
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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.
| project.rootProject.subprojects.any { getSubprojectPluginState(it)?.hasKgpPlugin == true } | |
| project.rootProject.allprojects.any { getSubprojectPluginState(it)?.hasKgpPlugin == true } |
|
Heads up on the Since this PR was opened, #193693 and #193717 landed on If
|
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.propertiesfile. 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-assistbot 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.