Repository navigation
[beta] [FGP] Offset split-APK versionCodes from a manifest-only versionCode - #196924
Conversation
…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. ## What changed - 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. ## Behavior change 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. ### Why this fails instead of logging an error 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. ### Cherry-pick note 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. ## Testing 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 | ## Known issues 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. ## Cherry-pick 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. ## 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. - [ ] 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)
|
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. |
There was a problem hiding this comment.
Code Review
This pull request refactors how the Android versionCode is resolved for split-per-abi builds in the Flutter Gradle Plugin. It defers reading the DSL versionCode to the onVariants phase and introduces a new ManifestVersionCodeTask to lazily extract the fallback versionCode from the main AndroidManifest.xml when it is omitted from the DSL. Feedback on the changes suggests replacing setErrorHandler(null) with an explicit custom ErrorHandler in ManifestVersionCodeTaskHelper to guarantee that no error output is printed to stderr across different JDK environments.
| // Suppress Xerces's default "[Fatal Error]" stderr output on malformed XML; | ||
| // readVersionCode catches SAXException and reports the failure instead. | ||
| setErrorHandler(null) | ||
| }.parse(manifest) |
There was a problem hiding this comment.
Setting setErrorHandler(null) configures the XML parser to use its default error handling behavior. Depending on the JDK version and the underlying XML parser implementation, the default behavior for fatal errors may still print [Fatal Error] messages directly to System.err before throwing the exception.
To guarantee that no error output is printed to System.err across all platforms and JDK environments, explicitly provide a custom ErrorHandler that does nothing for warnings/errors and rethrows the exception for fatal errors.
.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(e: org.xml.sax.SAXParseException) {}
override fun error(e: org.xml.sax.SAXParseException) {}
override fun fatalError(e: org.xml.sax.SAXParseException) {
throw e
}
})
}…sionCode (#196923) ### Issue Link: #196559 Companion beta cherry-pick: #196924 ### 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`. 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. [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? ### 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`). ### Bundled change and conflict resolution: This PR also cherry-picks [#195006](#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`.
The tool_test_durations.json change from flutter#196561 only rebalances CI shards. On 3.51 it moves test_test.dart into a Mac shard where an earlier test leaves SwiftPM plugin copies under dev/automated_tests/flutter_test/build, which the --experimental-faster-testing cases then try to run. Keeping 3.51's durations avoids that unrelated failure; the stable cherry-pick drops this file too.
|
autosubmit label was removed for flutter/flutter/196924, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 2 more review(s) in order to merge this PR.
|
8f89a71
into
flutter:flutter-3.51-candidate.0
…sionCode (#196923) ### Issue Link: flutter/flutter#196559 Companion beta cherry-pick: flutter/flutter#196924 ### Impact Description: [#193693](flutter/flutter#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](flutter/flutter#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](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. [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? ### 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`). ### Bundled change and conflict resolution: This PR also cherry-picks [#195006](flutter/flutter#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`.
Issue Link:
#196559
Companion stable cherry-pick: #196923
Impact Description:
#193693 migrated per-ABI
versionCodeoffsetting to AGP's public Variant API and shipped in 3.50.0 and 3.51.0-0.1.pre. Since #193693,--split-per-abibuilds read the baseversionCodeonly from theandroid {}DSL instead of falling back toAndroidManifest.xmlas 3.47 did. Apps that setandroid:versionCodeinAndroidManifest.xmlwithout a DSLversionCodeget the sameversionCodeon every split APK. The build only logs an error, and Google Play rejects split APKs that share aversionCode, blocking production releases.In addition, with
-P force-version-code-ignoring-abi=trueand noversionCodeset anywhere, Flutter shipped split APKs with noversionCodeattribute. Android reads a missingversionCodeas0, which installs fresh but fails to update a versioned build withINSTALL_FAILED_VERSION_DOWNGRADE. Google Play also rejects APKs without a positiveversionCode.This cherry-pick, #196561 (
a61f510cd52), readsandroid:versionCodefrom the main manifest in a cacheable task whenandroid {}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 offsetsversionCodevalues set infinalizeDsl, and fails instead of overflowingIntwhen the offset exceeds2147483647. It applied toflutter-3.51-candidate.0without conflicts. The code is byte-identical toa61f510cd52; the only difference is thatdev/bots/tool_test_durations.jsonkeeps 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
versionCodeinandroid {}or the main manifest,--split-per-abibuilds now fail (including with-P force-version-code-ignoring-abi=true). The error tells the developer to setversionCode = flutter.versionCodeindefaultConfig(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 aversionCode.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) indefaultConfigor on each product flavor inandroid/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:
flutter create app && cd app.versionCode = flutter.versionCodefromdefaultConfiginandroid/app/build.gradle.kts.android:versionCode="7"to<manifest>inandroid/app/src/main/AndroidManifest.xml.flutter build apk --split-per-abi, then inspect each APK inbuild/app/outputs/flutter-apk/withaapt2 dump badging. The split APKs reportversionCode1007(armeabi-v7a),2007(arm64-v8a), and4007(x86_64).ManifestVersionCodeTaskHelperTestandFlutterPluginTest(on AGP 9.1.1 and 9.3.1) andflutter_build_apk_split_per_abi_test.dart(including configuration-cache reuse withnewDslandenableLegacyApi=false).