Skip to content

[stable] [FGP] Offset split-APK versionCodes from a manifest-only versionCode - #196923

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

auto-submit[bot] merged 2 commits into
flutter:flutter-3.50-candidate.0from
reidbaker-agent:cherry-pick-196561-to-stable

Conversation

@reidbaker-agent

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

Copy link
Copy Markdown
Contributor

Issue Link:

#196559

Companion beta cherry-pick: #196924

Impact Description:

#193693 migrated per-ABI versionCode offsetting to AGP's public Variant API and shipped in 3.50.0 and 3.51.0-0.1.pre. Since #193693, --split-per-abi builds read the base versionCode only from the android {} DSL instead of falling back to AndroidManifest.xml as 3.47 did. Apps that set android:versionCode in AndroidManifest.xml without a DSL versionCode get the same versionCode on every split APK. The build only logs an error, and Google Play rejects split APKs that share a versionCode, blocking production releases.

In addition, with -P force-version-code-ignoring-abi=true and no versionCode set anywhere, Flutter shipped split APKs with no versionCode attribute. Android reads a missing versionCode as 0, which installs fresh but fails to update a versioned build with INSTALL_FAILED_VERSION_DOWNGRADE. Google Play also rejects APKs without a positive versionCode.

This cherry-pick, #196561 (a61f510cd52), reads android:versionCode from the main manifest in a cacheable task when android {} sets none, restoring 3.47's per-ABI offsets. With -P force-version-code-ignoring-abi=true, it applies that manifest value unchanged. It also offsets versionCode values set in finalizeDsl, and fails instead of overflowing Int when the offset exceeds 2147483647.

Behavior change: without a positive decimal versionCode in android {} or the main manifest, --split-per-abi builds now fail (including with -P force-version-code-ignoring-abi=true). The error tells the developer to set versionCode = flutter.versionCode in defaultConfig (or on each product flavor). Impact estimate for approvers (Googlers only): go/flutter-i196561-broken-users-impact estimates that fewer than 0.01% of Flutter Android apps hit this failure. Failing at build time is better than silently shipping split APKs that share a versionCode.

Changelog Description:

[flutter/196559] When building Android APKs with --split-per-abi and versionCode set only in AndroidManifest.xml, every split APK gets the same versionCode.
[flutter/195006] When building Android apps with Gradle's configuration cache enabled, Gradle can't store the cache entry, so it never reuses it.

Workaround:

Set versionCode = flutter.versionCode (or a literal integer) in defaultConfig or on each product flavor in android/app/build.gradle.kts (build.gradle).

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.
  2. Remove versionCode = flutter.versionCode from defaultConfig in android/app/build.gradle.kts.
  3. Add android:versionCode="7" to <manifest> in android/app/src/main/AndroidManifest.xml.
  4. Run flutter build apk --split-per-abi, then inspect each APK in build/app/outputs/flutter-apk/ with aapt2 dump badging. The split APKs report versionCode 1007 (armeabi-v7a), 2007 (arm64-v8a), and 4007 (x86_64).
  5. Covered by ManifestVersionCodeTaskHelperTest and FlutterPluginTest (on AGP 9.1.1 and 9.3.1) and flutter_build_apk_split_per_abi_test.dart (including configuration-cache reuse with newDsl and enableLegacyApi=false).

Bundled change and conflict resolution:

This PR also cherry-picks #195006 (fe070b10d2b, merged on master October 22; already in 3.51, not in 3.50). On 3.50, DependencyVersionChecker.configureMinSdkCheck captured Project and Variant inside doLast, breaking Gradle's configuration cache. Without #195006, #196561's configuration-cache integration test fails on flutter-3.50-candidate.0; bundling it also fixes configuration-cache reuse for 3.50.1 users.

PR #195006 applied cleanly. When cherry-picking #196561 (a61f510cd52), the only conflict was dev/bots/tool_test_durations.json, which does not exist on flutter-3.50-candidate.0 and was dropped (git rm). All other changed files are byte-identical to master.

…cyVersionChecker (flutter#195006)

Follow-up to flutter#194918; split out so that PR stays small for
cherry-picking.
Removes the `usesUnsupportedDependencyVersions`
(`OUT_OF_SUPPORT_RANGE_PROPERTY`) Gradle extra property from
`DependencyVersionChecker`, as `FlutterPlugin.apply` catches
`DependencyValidationException` directly and nothing else reads the
property.

Best the agent and my investigation work can find is that this was carry
over from when this code was in a build.gradle.kts file and we didnt
catch exceptions. I was found during manual review of flutter#194918

Part of flutter#166550.

<details><summary>Agent authored details</summary>

### Review Link (Part B diff only)

While [flutter#194918](flutter#194918) is open,
view only this PR's changes at:

https://github.com/flutter/flutter/pull/195006/files/5b5910facc17cd3d9ac87a594c187c6167f9ccc9..76d2f56c3e00ae37e016892bf7dcbe1c7fc8f675

### Background

`DependencyVersionChecker` set
`project.extra[OUT_OF_SUPPORT_RANGE_PROPERTY] = true`
(`"usesUnsupportedDependencyVersions"`) before throwing
`DependencyValidationException` and inside the `minSdkCheck` task
`doLast` action. That extra property originated when the dependency
version checker was applied as a standalone `.kts` script
(`dependency_version_checker.kts`) whose exception class could not be
referenced directly by `FlutterPlugin`. Because
`DependencyVersionChecker` and `DependencyValidationException` are
compiled in the same Kotlin module as `FlutterPlugin` and
[flutter#194918](flutter#194918) updated
`FlutterPlugin.apply` to catch `DependencyValidationException` directly,
the extra property has no remaining readers.

### Changes

1. **`DependencyVersionChecker.kt`**:
- Removes `OUT_OF_SUPPORT_RANGE_PROPERTY` and its 3-line comment
describing the Gradle extra property.
- Removes all 7 `project.extra.set(OUT_OF_SUPPORT_RANGE_PROPERTY, ...)`
calls (`checkDependencyVersions`, `configureMinSdkCheck`,
`checkGradleVersion`, `checkJavaVersion`, `checkAGPVersion` (x2), and
`checkKGPVersion`) and the `org.gradle.kotlin.dsl.extra` import.
- In `configureMinSdkCheck`, captures `rootDirPath`
(`project.rootDir.path`) and `minSdkVersion` outside `doLast` and passes
the task's `logger` to `checkMinSdkVersion(minSdkVersion, rootDirPath,
logger)` so the task action does not capture `Project`
(`packages/flutter_tools/gradle/AGENTS.md` §4).
- Updates the comment on `DependencyValidationException` to reference
`DependencyVersionChecker` instead of `the
dependency_version_checker.kts script`.
2. **`DependencyVersionCheckerTest.kt`**:
- Removes the `OUT_OF_SUPPORT_RANGE_PROPERTY`,
`ExtraPropertiesExtension`, and
`org.gradle.internal.extensions.core.extra` imports and mock setup,
keeping the `assertFailsWith<DependencyValidationException>` and logger
verification assertions in each test.
- Removed extra-property assertions (all redundant with
`assertFailsWith<DependencyValidationException>` or logger assertions
now that `OUT_OF_SUPPORT_RANGE_PROPERTY` is removed):
1. `Template versions are considered supported`: removed comment `//
Verify that the project was not marked as being out of support range.`
and `verify {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, false)
}`.
2. `AGP version in error range results in
DependencyValidationException`: removed `verify {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
3. `AGP version in warn range results in warning logs`: removed
`verify(exactly = 0) {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
4. `AGP version with unsupported major version results in
DependencyValidationException`: removed `verify {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
5. `AGP version above unsupported major version results in
DependencyValidationException`: removed `verify {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
6. `AGP version below unsupported major version is considered
supported`: removed `verify(exactly = 0) {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
7. `KGP version in error range results in
DependencyValidationException`: removed `verify {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
8. `KGP version in warn range results in warning logs`: removed
`verify(exactly = 0) {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
9. `AGP 9 built-in Kotlin skips KGP min version enforcement by default`:
removed `verify(exactly = 0) {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
10. `Java version in error range results in error logs`: removed
`verify(exactly = 1) {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
11. `Gradle version in error range results in
DependencyValidationException`: removed `verify {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
12. `Gradle version in warn range results in warning logs`: removed
`verify(exactly = 0) {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
13. `min SDK version in warn range results in warning logs`: removed
`verify(exactly = 0) {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
14. `min SDK version in error range results in
DependencyValidationException`: removed `verify(exactly = 1) {
mockExtraPropertiesExtension.set(OUT_OF_SUPPORT_RANGE_PROPERTY, true)
}`.
15. `checkMinSdkVersion throws error when in error range for min SDK
version` and `checkMinSdkVersion logs warning when in warning range for
min SDK version`: removed unused `mockExtraPropertiesExtension` local
setup.
16.
`MockProjectFactory.createMockProjectWithSpecifiedDependencyVersions`:
removed `// Extra properties extension` comment and `mockProject.extra`
stubbing; stubbed `mockTask.logger` on the registered task mock.

</details>

## 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.

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](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.

<!-- 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 fe070b1)
…lutter#196561)

Fixes flutter#196559

With `--split-per-abi`, Flutter gives each split APK the versionCode
`ABI * 1000 + base`. Since flutter#193693, Flutter takes `base` only from the
`android {}` DSL. Apps that set `android:versionCode` only in
`AndroidManifest.xml` got the same versionCode on every split APK, and
Google Play rejects APKs that share a versionCode. The build only logged
an error.

- If the DSL sets no versionCode, a new cacheable task,
`resolveManifestVersionCode<Variant>` (`ManifestVersionCodeTask`), reads
`android:versionCode` from the main manifest and writes it to a file.
Each split output's versionCode is a provider of that task's output, so
AGP's manifest task runs after it.
- The base is the one AGP itself uses. In AGP 9.3.1, a DSL-less variant
versionCode comes only from the main source set's manifest
(`src/main/AndroidManifest.xml` unless `sourceSets.main` moves it), and
AGP injects it into the merged manifest over every overlay when it is
positive. Flutter reads the same file and requires the same positive
integer. Build-type, flavor, and generated manifests are not read.
- The main manifest is the last entry of
`variant.sources.manifests.all`, which can also contain manifests that
other tasks generate (for example Flutter's engine flags manifest with
`-Pflutter.engineShellArgs`). The list is a task input, so it is only
read when the task runs.
- Nothing is read at configuration time. The code makes no legacy
variant API calls, so it works with
`android.compatibility.enableLegacyApi=false`, `android.newDsl=true` and
`android.builtInKotlin=true`.
- The manifests are task inputs, so a manifest edit reaches the next
build even when the configuration cache is reused.
- When the DSL sets a versionCode, on `defaultConfig` or on a product
flavor, nothing changes.

If Flutter cannot find a base versionCode in `android {}` or the main
manifest, a `--split-per-abi` build now fails with or without `-P
force-version-code-ignoring-abi=true`. Before, builds without the flag
only logged an error. With the flag and no DSL versionCode, Flutter
skipped its check—a pre-existing gap in 3.50.0 (3.47.9 skipped the
offset under the flag too). With `-P
force-version-code-ignoring-abi=true` and a valid main-manifest
`android:versionCode`, every split APK gets that value unchanged (a DSL
versionCode is still left to AGP).

When `android {}` sets no versionCode, the build fails if:

- the main manifest sets no `android:versionCode` (even if a build-type
or flavor manifest does),
- the main manifest's value is not a decimal integer, such as a `${vc}`
placeholder, an `@integer/...` resource, or `0x10`, or
- the main manifest's value is 0 or less, or larger than 2147483647. AGP
does not inject a value of 0 or less, and Google Play requires a
positive versionCode.

The error names the variant and the cause. It tells you to set
`versionCode = flutter.versionCode` in `defaultConfig` (or on each
product flavor):

> Flutter cannot give the split APKs of variant 'debug' a versionCode:
its android {} block sets no versionCode, and
…/src/main/AndroidManifest.xml does not set android:versionCode. Android
reads an APK without a versionCode as versionCode 0. Google Play rejects
such APKs, and they cannot be installed over a build of the app that has
a versionCode. Set versionCode = flutter.versionCode in defaultConfig
(or on each product flavor).

The same error applies with and without `-P
force-version-code-ignoring-abi=true`. Without Flutter's check, AGP
either omits `versionCode` or fails:

- Without a positive versionCode in the main manifest, AGP builds split
APKs with no versionCode (`aapt2 dump badging` shows `versionCode=''`).
Android reads a missing versionCode as `0`: fresh installs succeed, but
Google Play rejects those APKs, and updating a build with a positive
versionCode fails with `INSTALL_FAILED_VERSION_DOWNGRADE`.
- With a value that is not a decimal integer, AGP itself fails: `Error
while evaluating property 'variantOutputs.$0.versionCode' of task
':app:createDebugCompatibleScreenManifests'. >
java.lang.NumberFormatException: For input string: "0x10"`. AGP parses
this attribute with `Integer.parseInt` (seen with `javap` on
`ManifestDataKt` in AGP 9.1.1 and 9.3.1), so a plain `flutter build apk`
without `--split-per-abi` fails the same way.

A corner-case audit of this PR found two more problems, which are fixed
here too:

- **A versionCode set in `androidComponents.finalizeDsl` is offset
again.** Since flutter#193693, Flutter read the DSL versionCodes in its own
`finalizeDsl` callback. That callback runs before the app's, because the
app applies Flutter in its `plugins {}` block. So `finalizeDsl {
it.defaultConfig.versionCode = 55 }` was not seen, while Flutter 3.47
gave 1055 / 2055 / 4055. Flutter now reads the DSL on its first
`onVariants` call. AGP runs `onVariants` only after every `finalizeDsl`
callback (`BasePlugin.createAndroidTasks` runs
`executeDslFinalizationBlocks` before `createVariants`), and the DSL can
still be read then.
- **A split APK versionCode that overflows an `Int` fails the build.**
Before, `versionCode = 2147482000` wrapped around without a warning:
arm64-v8a and x86_64 got negative values, and all 3 APKs ended up with
versionCode 2147483000. Now both DSL and manifest versionCodes fail
with:

> Flutter cannot give the x86_64 split APK of variant 'debug' a
versionCode: 4000 + 2147482000 is larger than 2147483647, the largest
versionCode Android allows. Lower the versionCode. If you do not publish
these APKs on Google Play, you can instead pass -P
force-version-code-ignoring-abi=true to give every split APK the
versionCode 2147482000.

  The largest base that works for all 3 ABIs is 2147479647.

We tried keeping the old "log an error and continue" behavior for the
case where no versionCode is set anywhere, and it doesn't work under the
new DSL:

- Flutter can only learn the manifest value at execution time, so it has
to give AGP a lazy provider for each split output's `versionCode`.
- If that provider has no value, AGP's `process<Variant>MainManifest`
fails with "property 'versionCode' has no value". Gradle has no API to
fall back to AGP's original value.
- The only way to avoid setting the property is to decide at
configuration time whether a manifest versionCode exists. That needs a
configuration-time read, which `enableLegacyApi=false` and the new DSL
don't allow.

So the choice is Flutter's clear error, or AGP's unclear one. The builds
this now fails were already producing split APKs that all share a
versionCode, which Google Play rejects.

This PR is meant to be cherry-picked to 3.50 to fix flutter#196559. That means
a 3.50 point release would turn the previous error log into a build
failure for apps that set no versionCode anywhere. Reviewers should
decide explicitly whether that's acceptable for 3.50. The alternative is
to land the failure on master only. If it ships, the release notes
should say how to fix the error: set `versionCode = flutter.versionCode`
in `defaultConfig`.

Impact analysis for cherry-pick approvers (Googlers only):
[go/flutter-i196561-broken-users-impact](http://go/flutter-i196561-broken-users-impact).
It estimates that the new failure affects fewer than 0.01% of Flutter
Android apps, and explains why failing is better than silently shipping
split APKs that share one versionCode.

Follow-up for `force-version-code-ignoring-abi` without a DSL
versionCode (657e7d0):

- `FlutterPluginTest` adds a case for
`force-version-code-ignoring-abi=true` with no DSL versionCode (verifies
`ManifestVersionCodeTaskHelper.registerTask` is wired without the
per-ABI offset, giving `7` rather than `2007`) and checks that the DSL +
flag path sets no provider. `ManifestVersionCodeTaskHelperTest` checks
the updated message. All 298 Gradle unit tests pass on AGP 9.1.1 and
9.3.1; ktlint 1.5.0 is clean.
- `flutter_build_apk_split_per_abi_test` checks that `--split-per-abi`
without a versionCode fails both with and without `-P
force-version-code-ignoring-abi=true`.
- Emulator verification on `Pixel_9_API_35` (`flutter build apk --debug
--split-per-abi`, AGP 9.3.1; "over `vc=7`" means `adb install -r` over
an installed `versionCode=7` build):

| Case | 3.50.0 | PR before (`ebfd1ed`) | PR after (`657e7d0`) |
| --- | --- | --- | --- |
| No DSL, no manifest `vc`, `force` | Builds `vc=''` ×3; fresh install
OK (`0`); over `vc=7`: `INSTALL_FAILED_VERSION_DOWNGRADE` | Same as
3.50.0 | Fails at `resolveManifestVersionCodeDebug` |
| No DSL, manifest `0`, `force` | n/a | `vc=''` ×3; fresh OK (`0`); over
`vc=7`: `DOWNGRADE` | Fails (`"0" … is not positive`) |
| No DSL, manifest `7`, `force` | n/a | 7 / 7 / 7; installs OK | 7 / 7 /
7; fresh OK, over `vc=7` OK |
| No DSL, no manifest `vc`, no `force` | Warning only; `vc=''`; over
`vc=7`: `DOWNGRADE` | Fails | Fails (updated message) |
| No DSL, manifest `7`, no `force` | 7 / 7 / 7 + warning | n/a | 1007 /
2007 / 4007; over `vc=7` OK |
| DSL `--build-number=5` ± `force` | n/a | n/a | `force`: 5 / 5 / 5; no
`force`: 1005 / 2005 / 4005 |

Follow-up for the corner-case audit (254132c):

- `FlutterPluginTest` has 3 new cases:
- A versionCode that a later `finalizeDsl` callback sets is offset. This
case fails when the DSL is read at apply time.
- On the DSL path, `armeabi-v7a` still gets 2147483000, and then
`arm64-v8a` fails with the overflow message.
- `splitApkVersionCode` is tested at the boundary, `Int.MAX_VALUE -
4000` and `- 3999`.
- `ManifestVersionCodeTaskHelperTest` covers `${versionCode}`,
`@integer/version_code`, `0x10`, `+7`, `2147483647`, `2147483648`,
`+2147483648` and `-99999999999`. It also checks that the error does not
mention the force flag.
- All 297 Gradle unit tests pass on the default AGP 9.1.1 and with
`-Pflutter.internal.agpVersion=9.3.1`. ktlint 1.5.0 is clean.
- `flutter_build_apk_split_per_abi_test` has a new case. With `newDsl`,
`builtInKotlin` and `enableLegacyApi=false`, the app sets `versionCode =
55` in `finalizeDsl`, and the test expects 1055 / 2055 / 4055. All 8
cases pass locally in 2m31s, and the new case takes 18s.
`tool_test_durations.json` is scaled by that.
- Manual `--debug --split-per-abi` builds on AGP 9.1.1 and 9.3.1, with
`newDsl`, `builtInKotlin` and `enableLegacyApi=false`:

| Case | Result (armv7 / arm64 / x86_64) |
| --- | --- |
| `finalizeDsl` sets 55, main manifest sets none, `./gradlew
:app:processDebugManifest -Psplit-per-abi=true --configuration-cache
--configuration-cache-problems=fail` | 1055 / 2055 / 4055 in the merged
manifests. Before this follow-up, the build failed with "does not set
android:versionCode". |
| Same with `flutter build apk` | 1055 / 2055 / 4055 |
| Main manifest `2147482000` | Fails with the overflow message, inside
AGP's "Error while evaluating property 'variantOutputs.$1.versionCode'"
|
| Main manifest `2147479647` | 2147480647 / 2147481647 / 2147483647 |
| `defaultConfig` `2147482000` (AGP 9.3.1) | Fails during configuration
with the overflow message |
| Main manifest sets none, or `0x10` | Fails with the new message |

- Force flag on AGP 9.3.1 with no DSL versionCode, at 254132c
(addressed in 657e7d0 above): if the main manifest sets none or `0`,
the build exits 0 and all 3 APKs have `versionCode=''`. With `${myVc}`
(the placeholder is set), `@integer/app_version_code` or `0x10`, AGP
fails with `NumberFormatException`.

Earlier testing:

- New unit tests: `ManifestVersionCodeTaskHelperTest` (positive,
whitespace, a custom Android namespace prefix, missing, placeholder, 0
and negative, a DOCTYPE, malformed XML without stderr output, a missing
file, UTF-16), plus 2 `FlutterPluginTest` cases. One runs the task with
a debug overlay and the main manifest written after configuration, and
checks that the main manifest's value is used and the failure message.
The other uses a task-generated manifest, and checks that building the
task graph does not query it. All 293 Gradle unit tests pass, and ktlint
1.5.0 is clean.
- Matrix verification (`DependencyVersionChecker.kt` range): verified on
both AGP 9.3.1 (template default, Gradle 9.5.0) and AGP 9.1.1 (minimum
supported, Gradle 9.3.1) — all 293 Gradle unit tests
(`-Pflutter.internal.agpVersion=9.1.1`) and all 7
`flutter_build_apk_split_per_abi_test` cases pass on AGP 9.1.1.
- `flutter_build_apk_split_per_abi_test` has 3 new cases, which read
versionCodes with `aapt2 dump badging`. All 7 cases pass locally.
- main manifest `7`, a `src/debug` overlay `9` with `tools:replace`, and
the generated engine flags manifest: expect 1007/2007/4007;
- manifest-only with the configuration cache, `newDsl` and
`enableLegacyApi=false`: build, rebuild while reusing the cache, edit
the manifest, and expect the new value;
  - no versionCode in the main manifest: the build fails.
- Mutation checks: with the plugin change reverted, the manifest-only
case fails (expected 1007, got 7). With an earlier version of this
change that read the files through `java.io`, the configuration cache
case fails (expected 1006, got 1007). With the earlier `flatMap` over
`ManifestFiles.all`, a build with `-Pflutter.engineShellArgs` fails with
`Querying the mapped value of … before task
':app:generateEngineFlagsManifestDebug' has completed is not supported`,
and so does the generated-manifest `FlutterPluginTest` case
(`InvalidUserCodeException`).
- Manual `flutter build apk --release --split-per-abi` on an app with
`newDsl` and `builtInKotlin` on and `enableLegacyApi=false`:

| Case | AGP | Result (armv7 / arm64 / x86_64) |
| --- | --- | --- |
| Manifest-only `7` | 9.3.1, 9.1.1 | 1007 / 2007 / 4007 |
| Manifest-only, configuration cache reused, then edited 8 → 6 | 9.3.1 |
1008 → 1006 (and so on) |
| `defaultConfig` `5` | 9.3.1 | 1005 / 2005 / 4005 (unchanged) |
| Flavor `free` = 11; flavor `paid` falls back to `defaultConfig` 5 |
9.3.1 | 1011… / 1005… (unchanged) |
| Overlay `${vc}`, `tools:remove`, or no versionCode | 9.3.1 | Build
fails with the message |
| Same, with `-P force-version-code-ignoring-abi=true` | 9.3.1 | 7 / 7 /
7 |

The table above ran before the review follow-ups. Flutter now reads only
the main manifest, so the overlay rows fail unless the main manifest
sets a positive versionCode, and the "overlay `9`, main sets none" row
below now fails with the message. After the first follow-up, I ran these
`--debug --split-per-abi` builds (and one `--release`) on a default
`flutter create` app with AGP 9.3.1:

| Case | Result (armv7 / arm64 / x86_64) |
| --- | --- |
| `src/debug` overlay `9` with `tools:replace`, main `7` | 1007 / 2007 /
4007 (a non-split build also gets 7) |
| `src/debug` overlay `9`, main sets none | 1009 / 2009 / 4009 |
| `src/debug` overlay `tools:remove="android:versionCode"`, main `7` |
1007 / 2007 / 4007 |
| Main `7`, `-P flutter.engineShellArgs=...`, debug and `--release` |
1007 / 2007 / 4007 |

With `org.gradle.configuration-cache.problems=fail`, `flutter build apk`
(debug and release) still fails because `FlutterTask`
(`compileFlutterBuild<Variant>`) reads `Task.project` at execution time.
That also happens on master. The configuration cache test sets
`problems=warn` for that reason.

On `--split-per-abi` builds where `android {}` sets no `versionCode`, a
`variant.sources.manifests.addGeneratedManifestFile` task that also
reads `output.versionCode` hits a circular task dependency with
`resolveManifestVersionCode<Variant>` both with and without `-P
force-version-code-ignoring-abi=true`; setting `versionCode =
flutter.versionCode` in `defaultConfig` avoids it.

A 3-way merge of this PR onto `flutter-3.50-candidate.0` (`git
merge-tree`) is clean except `dev/bots/tool_test_durations.json`, which
does not exist on that branch, so the cherry-pick should drop that file.

- [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.
- [ ] 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 a61f510)
@reidbaker-agent
reidbaker-agent requested a review from a team as a code owner November 18, 2026 21:43
@reidbaker-agent
reidbaker-agent requested review from mboetger and removed request for a team November 18, 2026 21:43
@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 the CICD Run CI/CD label Nov 18, 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 refactors the version code resolution logic for Android split-per-abi builds in the Flutter Gradle Plugin. It removes the unsupported dependency version property from the version checker and defers the reading of DSL version codes to the onVariants phase. Additionally, it introduces ManifestVersionCodeTask and ManifestVersionCodeTaskHelper to lazily extract the fallback versionCode from the main AndroidManifest.xml when it is omitted in the DSL, resolving configuration cache and task dependency issues. Corresponding unit and integration tests have been added. Feedback is provided regarding the XML parser's error handler in ManifestVersionCodeTaskHelper, where providing an explicit empty ErrorHandler is recommended over passing null to ensure reliable stderr suppression across different JDK environments.

Comment on lines +127 to +131
.apply {
// Suppress Xerces's default "[Fatal Error]" stderr output on malformed XML;
// readVersionCode catches SAXException and reports the failure instead.
setErrorHandler(null)
}.parse(manifest)

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

Passing null to setErrorHandler does not reliably suppress the default error handler's output to System.err across all JDKs and environments; instead, it typically restores the default parser behavior, which may still print fatal errors or warnings to stderr. To ensure all stderr output from the XML parser is suppressed, provide an explicit ErrorHandler implementation that does nothing.

            .apply {
                // Suppress Xerces's default "[Fatal Error]" stderr output on malformed XML;
                // readVersionCode catches SAXException and reports the failure instead.
                setErrorHandler(object : org.xml.sax.ErrorHandler {
                    override fun warning(exception: org.xml.sax.SAXParseException) {}
                    override fun error(exception: org.xml.sax.SAXParseException) {}
                    override fun fatalError(exception: org.xml.sax.SAXParseException) {}
                })
            }.parse(manifest)

@reidbaker reidbaker added the cp: review Cherry-picks in the review queue 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 👍

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

auto-submit Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196923, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label.

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit
auto-submit Bot merged commit 53eaa7d 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
…onCode (#196924)

### Issue Link:
#196559

Companion stable cherry-pick: #196923

### Impact Description:
[#193693](#193693) migrated per-ABI `versionCode` offsetting to AGP's public Variant API and shipped in 3.50.0 and 3.51.0-0.1.pre. Since #193693, `--split-per-abi` builds read the base `versionCode` only from the `android {}` DSL instead of falling back to `AndroidManifest.xml` as 3.47 did. Apps that set `android:versionCode` in `AndroidManifest.xml` without a DSL `versionCode` get the same `versionCode` on every split APK. The build only logs an error, and Google Play rejects split APKs that share a `versionCode`, blocking production releases.

In addition, with `-P force-version-code-ignoring-abi=true` and no `versionCode` set anywhere, Flutter shipped split APKs with no `versionCode` attribute. Android reads a missing `versionCode` as `0`, which installs fresh but fails to update a versioned build with `INSTALL_FAILED_VERSION_DOWNGRADE`. Google Play also rejects APKs without a positive `versionCode`.

This cherry-pick, [#196561](#196561) (`a61f510cd52`), reads `android:versionCode` from the main manifest in a cacheable task when `android {}` sets none, restoring 3.47's per-ABI offsets. With `-P force-version-code-ignoring-abi=true`, it applies that manifest value unchanged. It also offsets `versionCode` values set in `finalizeDsl`, and fails instead of overflowing `Int` when the offset exceeds `2147483647`. It applied to `flutter-3.51-candidate.0` without conflicts. The code is byte-identical to `a61f510cd52`; the only difference is that `dev/bots/tool_test_durations.json` keeps its 3.51 contents, because master's test-duration data changes how the Mac tool integration tests are sharded on 3.51.

Behavior change: without a positive decimal `versionCode` in `android {}` or the main manifest, `--split-per-abi` builds now fail (including with `-P force-version-code-ignoring-abi=true`). The error tells the developer to set `versionCode = flutter.versionCode` in `defaultConfig` (or on each product flavor). Impact estimate for approvers (Googlers only): [go/flutter-i196561-broken-users-impact](http://go/flutter-i196561-broken-users-impact) estimates that fewer than 0.01% of Flutter Android apps hit this failure. Failing at build time is better than silently shipping split APKs that share a `versionCode`.

### Changelog Description:
[flutter/196559] When building Android APKs with --split-per-abi and versionCode set only in AndroidManifest.xml, every split APK gets the same versionCode.

The stable cherry-pick (#196923) also adds a [flutter/195006] entry for the configuration cache fix it bundles. That fix is already in 3.51, so this beta cherry-pick has no second entry.

### Workaround:
Set `versionCode = flutter.versionCode` (or a literal integer) in `defaultConfig` or on each product flavor in `android/app/build.gradle.kts` (`build.gradle`).

### 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`.
2. Remove `versionCode = flutter.versionCode` from `defaultConfig` in `android/app/build.gradle.kts`.
3. Add `android:versionCode="7"` to `<manifest>` in `android/app/src/main/AndroidManifest.xml`.
4. Run `flutter build apk --split-per-abi`, then inspect each APK in `build/app/outputs/flutter-apk/` with `aapt2 dump badging`. The split APKs report `versionCode` `1007` (`armeabi-v7a`), `2007` (`arm64-v8a`), and `4007` (`x86_64`).
5. Covered by `ManifestVersionCodeTaskHelperTest` and `FlutterPluginTest` (on AGP 9.1.1 and 9.3.1) and `flutter_build_apk_split_per_abi_test.dart` (including configuration-cache reuse with `newDsl` and `enableLegacyApi=false`).
@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.

4 participants