Skip to content

[stable] [flutter_tools] Do not copy app-only build type properties onto library plugins - #196756

Merged
auto-submit[bot] merged 1 commit into
flutter:flutter-3.50-candidate.0from
reidbaker-agent:cherry-pick-196692-to-stable
Nov 18, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:flutter-3.50-candidate.0from
reidbaker-agent:cherry-pick-196692-to-stable

Conversation

@reidbaker-agent

@reidbaker-agent reidbaker-agent commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Issue Link:

#196412
and #196696

Companion beta cherry-pick: #196757

Impact Description:

#191606, part of the migration to AGP's public Variant API, changed how the Flutter Gradle Plugin creates missing app build types on plugin projects. It shipped in 3.50.0 and in the current beta, 3.51.0-0.1.pre. Up to 3.47, library plugins received a compatible build type without app-only properties (#172704). Since #191606, PluginHandler called initWith(appBuildType) for every plugin. In AGP 9, initWith copies every build type property, and AGP rejects several of them in a library module: applicationIdSuffix (#196412), isShrinkResources (including any custom build type created with initWith(getByName("release")), because Flutter enables isShrinkResources on release by default; #196696), buildConfigFields, and resValues. Because Gradle configures every build type of every subproject, affected apps fail to configure even in debug mode (flutter run). In addition, copying isMinifyEnabled onto library plugins caused R8 to strip plugin classes on custom minified build types (Missing class ...Plugin).

This cherry-pick, #196692 (534fb4d6247), restores separate handling for library plugins: plugins built as apps keep initWith, while library plugins receive only matchingFallbacks and isDebuggable (skipping app-only properties and isMinifyEnabled, because the app's R8 pass shrinks plugin code). It applied to flutter-3.50-candidate.0 without conflicts (0 diff vs 534fb4d6247).

Changelog Description:

[flutter/196412] When building an Android app with plugins and custom or app-only buildType settings, Gradle configuration fails.

Workaround:

Pre-create the custom or profile build type in every library subproject from the root android/build.gradle.kts before Flutter copies it (subprojects { pluginManager.withPlugin("com.android.library") { extensions.configure<com.android.build.api.dsl.LibraryExtension>("android") { buildTypes.maybeCreate("profile") } } }), or for applicationIdSuffix set it via androidComponents.onVariants.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

  1. Run flutter create app && cd app && flutter pub add shared_preferences.
  2. In android/app/build.gradle.kts, set applicationIdSuffix = ".profile" on profile and add create("staging") { initWith(getByName("release")) } under buildTypes.
  3. Run flutter build apk --debug, flutter build apk --profile, and ./gradlew -p android :app:assembleStaging. All three succeed, and aapt2 dump badging on the profile APK shows package suffix .profile.
  4. Covered by PluginHandlerTest and android_plugin_example_app_build_test.dart (verified on both AGP 9.1.1 and AGP 9.3.1).

…ry plugins (flutter#196692)

Fixes flutter#196412
Fixes flutter#196696
Part of flutter#196689

Since Flutter 3.50, an app fails to configure, even in debug mode, when
it uses a plugin and one of its build types sets something that a
library module can't have. Examples are `applicationIdSuffix` on
`profile` (flutter#196412), `isShrinkResources` (flutter#196696) on a custom build
type, or a `buildConfigField` or `resValue`. Example error:

```
A problem occurred configuring project ':jni'.
> com.android.builder.errors.EvalIssueException: Library projects cannot set applicationIdSuffix. applicationIdSuffix is set to '.profile' in build type 'profile'.
```

This is a regression of flutter#169215. flutter#191606 changed the Flutter Gradle
Plugin to copy each app build type that a plugin lacks onto the plugin
with `initWith(appBuildType)`. In AGP 9.3.1, `initWith` copies every
build type property (`AbstractBuildType.initWith`,
`BaseConfigImpl._initWith`, `BuildType._initWith`), including several
that AGP rejects in a library:

| Property | AGP error in the library |
| --- | --- |
| `applicationIdSuffix` | `Library projects cannot set
applicationIdSuffix` |
| `isShrinkResources` | `Resource shrinker cannot be used for
libraries.` The check runs inside `initWith`, so the value can't be
reset afterwards. |
| `buildConfigFields` | `contains custom BuildConfig fields, but the
feature is disabled` |
| `resValues` | `contains custom resource values, but the feature is
disabled` |

The `this is ApplicationBuildType` check that was meant to keep app-only
properties away from library plugins is always true. AGP uses one build
type class for every module type, and it implements
`ApplicationBuildType`, `LibraryBuildType`, `DynamicFeatureBuildType`
and `TestBuildType`.

This PR:
- Uses `initWith` only for plugins that are built as apps
(`isBuiltAsApp`, as flutter#172704 did). An app accepts every build type
property, and `initWith` already copies `isDebuggable`, so app plugins
no longer set it separately.
- Gives library plugins only `matchingFallbacks` and `isDebuggable`, in
a separate `copyLibraryBuildTypeProperties` function:
- `matchingFallbacks` lets the plugin's own dependencies resolve.
flutter#191606 meant to add it.
- `isDebuggable` isn't in the public library DSL, but library variants
still read it, for example for `BuildConfig.DEBUG`, R8's debuggable flag
and the CMake build type of FFI plugins. It is set through the
`ApplicationBuildType` interface that AGP's build type class implements,
as in Flutter 3.47.
- `isMinifyEnabled` is no longer copied (3.47 copied it). A minified
library build type makes AGP run R8 on the plugin with only the plugin's
keep rules. That removes the plugin class that
`GeneratedPluginRegistrant` uses, and the app's R8 run fails with
`Missing class
io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin`. The app's
R8 run already shrinks plugin code.
- Updates the unit tests. The library build type mock implements both
the library and application interfaces, like the real AGP class. The
test checks that `initWith` isn't called and that `isMinifyEnabled`
isn't set.
- Extends `android_plugin_example_app_build_test.dart`, which builds the
example app of the `plugin` and `plugin_ffi` templates against the real
AGP. Before the first build, the test now adds `applicationIdSuffix`,
`versionNameSuffix`, `buildConfigField` and `resValue` to the `profile`
build type, and adds a `staging` build type with `isMinifyEnabled` and
`isShrinkResources`. For the `plugin` template, it also runs `./gradlew
:app:assembleStaging`. The earlier tests were mock-only and checked that
`initWith` was called, so they could not catch this.

Verified locally on 3.50.0 and master:
- On stock 3.50.0, the repro from flutter#196412 fails, and so do apps with
only `isShrinkResources` or only `buildConfigField`. 3.47.9 builds them.
- With this change, the flutter#196412 repro builds with `--debug` and
`--profile`. `aapt2 dump badging` shows package
`com.example.repro350.profile` and versionName `1.0.0-PROFILE` for the
profile APK. An app with a `staging` build type that uses
`initWith(release)`, `isMinifyEnabled` and `isShrinkResources` builds
with `./gradlew :app:assembleStaging`.
- On stock master and stock 3.50.0, both cases in
`android_plugin_example_app_build_test.dart` fail with `Resource
shrinker cannot be used for libraries.` and `contains custom BuildConfig
fields, but the feature is disabled`. With this change, both cases pass
on master and 3.50.0. If `isMinifyEnabled` is copied again, the `plugin`
case fails with `R8: Missing class
com.example.plugin_test.PluginTestPlugin`.
- All Flutter Gradle Plugin unit tests pass on master against the
default AGP and AGP 9.3.1, and on 3.50.0. ktlint and `dart analyze` are
clean.
- Tested on both ends of the supported AGP range: AGP 9.3.1 (the
template default, with Gradle 9.5.0) and AGP 9.1.1 (the minimum in
`DependencyVersionChecker.kt`, with Gradle 9.3.1). On AGP 9.1.1, both
cases of `android_plugin_example_app_build_test.dart` pass with this
change, covering the release APK, `:app:assembleStaging` and a profile
APK. Without the change, they fail with the shrinker and BuildConfig
errors. The Flutter Gradle Plugin unit tests also pass with
`-Pflutter.internal.agpVersion=9.1.1`.

I intend to cherry-pick this into 3.50.x. The change applies to 3.50
without edits, because the 3 files it changes are the same on 3.50.0 and
master. I ran the tests above on 3.50.0 with this change applied.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

(cherry picked from commit 534fb4d)
@reidbaker-agent
reidbaker-agent requested a review from a team as a code owner November 17, 2026 04:26
@reidbaker-agent
reidbaker-agent requested review from reidbaker and removed request for a team November 17, 2026 04:26
@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@reidbaker reidbaker added cp: review Cherry-picks in the review queue CICD Run CI/CD labels Nov 17, 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 updates PluginHandler.kt to selectively copy build type properties from the app project to library plugin projects instead of using initWith for all plugins, preventing the copying of app-only properties that the Android Gradle Plugin rejects in libraries. Unit tests in PluginHandlerTest.kt and integration tests in android_plugin_example_app_build_test.dart have been updated and added to verify this behavior. There are no review comments, and I have no feedback to provide.

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026

@justinmc justinmc 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.

LGTM 👍

@auto-submit
auto-submit Bot merged commit 4b70281 into flutter:flutter-3.50-candidate.0 Nov 18, 2026
6 checks passed
auto-submit Bot pushed a commit that referenced this pull request Nov 18, 2026
…o library plugins (#196757)

### Issue Link:
#196412
and #196696

Companion stable cherry-pick: #196756

### Impact Description:
[#191606](#191606), part of the migration to AGP's public Variant API, changed how the Flutter Gradle Plugin creates missing app build types on plugin projects. It shipped in 3.50.0 and in the current beta, 3.51.0-0.1.pre. Up to 3.47, library plugins received a compatible build type without app-only properties (#172704). Since #191606, `PluginHandler` called `initWith(appBuildType)` for every plugin. In AGP 9, `initWith` copies every build type property, and AGP rejects several of them in a library module: `applicationIdSuffix` (#196412), `isShrinkResources` (including any custom build type created with `initWith(getByName("release"))`, because Flutter enables `isShrinkResources` on `release` by default; #196696), `buildConfigFields`, and `resValues`. Because Gradle configures every build type of every subproject, affected apps fail to configure even in `debug` mode (`flutter run`). In addition, copying `isMinifyEnabled` onto library plugins caused R8 to strip plugin classes on custom minified build types (`Missing class ...Plugin`).

This cherry-pick, [#196692](#196692) (`534fb4d6247`), restores separate handling for library plugins: plugins built as apps keep `initWith`, while library plugins receive only `matchingFallbacks` and `isDebuggable` (skipping app-only properties and `isMinifyEnabled`, because the app's R8 pass shrinks plugin code). It applied to `flutter-3.51-candidate.0` without conflicts (`0` diff vs `534fb4d6247`).

### Changelog Description:
[flutter/196412] When building an Android app with plugins and custom or app-only buildType settings, Gradle configuration fails.

### Workaround:
Pre-create the custom or `profile` build type in every library subproject from the root `android/build.gradle.kts` before Flutter copies it (`subprojects { pluginManager.withPlugin("com.android.library") { extensions.configure<com.android.build.api.dsl.LibraryExtension>("android") { buildTypes.maybeCreate("profile") } } }`), or for `applicationIdSuffix` set it via `androidComponents.onVariants`.

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
1. Run `flutter create app && cd app && flutter pub add shared_preferences`.
2. In `android/app/build.gradle.kts`, set `applicationIdSuffix = ".profile"` on `profile` and add `create("staging") { initWith(getByName("release")) }` under `buildTypes`.
3. Run `flutter build apk --debug`, `flutter build apk --profile`, and `./gradlew -p android :app:assembleStaging`. All three succeed, and `aapt2 dump badging` on the profile APK shows package suffix `.profile`.
4. Covered by `PluginHandlerTest` and `android_plugin_example_app_build_test.dart` (verified on both AGP 9.1.1 and AGP 9.3.1).
@victorsanni victorsanni mentioned this pull request Nov 18, 2026
11 tasks done
auto-submit Bot pushed a commit that referenced this pull request Nov 19, 2026
Adds `CHANGELOG.md` entries for the 3.50.1 stable hotfix (#196756, #196721, #196127, #196035, #196418, #196800, #196796, #196895, #196383, #196923). Omits the infra-only #196760 and the `engine.version` sync #196932.

Tracker: #196743

### Edits to cherry-pick changelog descriptions
- All entries use the cherry-pick PR's "Changelog Description" verbatim, except for backticks around code terms (#196756, #196418, #196895, #196923) and a comma and trailing period in the #196418 entry.
- #196923 also cherry-picks #195006, so it has two entries, as listed in its "Changelog Description".

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](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants