Skip to content

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

Merged
reidbaker merged 17 commits into
flutter:masterfrom
reidbaker-agent:vcfix-manifest-fallback
Nov 18, 2026
Merged

reidbaker merged 17 commits into
flutter:masterfrom
reidbaker-agent:vcfix-manifest-fallback

Conversation

@reidbaker-agent

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

Copy link
Copy Markdown
Contributor

Fixes #196559

With --split-per-abi, Flutter gives each split APK the versionCode ABI * 1000 + base. Since #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 [AGP 9.1.0 Migration #7] Migrate the flutter-apk copy and per-ABI versionCode to the variant API #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 #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. 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

@github-actions github-actions Bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. d: docs/ flutter/flutter/docs, for contributors labels Nov 13, 2026
@reidbaker
reidbaker self-requested a review November 13, 2026 21:41
reidbaker-agent added a commit to reidbaker-agent/website that referenced this pull request Nov 16, 2026
- Apply plain-language and flutter/website style conventions across both
  3.50 Android build breaking-change pages (imperative task headings,
  explicit affected vs unaffected triage, `-` list markers, no manual
  table footnotes or inflected code spans, and semantic line breaks).
- Fix technical findings verified against Flutter 3.50.0:
  - Clarify how to inspect current AGP/Gradle/KGP/JDK versions and what
    `flutter analyze --suggestions` actually reports.
  - Complete the trimmed AGP error message, add 3.44 template Gradle
    9.1.0 and Gradle/KGP no-advance-warning ranges, and fix the broken
    AGP/Gradle compatibility table anchor (`about-agp#updating-gradle`).
  - Clarify that KGP still must be >= 2.4.10 when `builtInKotlin=false`.
  - Fix `copyFlutterApks<Variant>` visibility (`./gradlew tasks --all`),
    3.47 library plugin build-type copying, softened `LibraryBuildType`
    debuggability note, `onVariants` task lookup (`tasks.matching`),
    preview `compileSdk` comparison, `flutter run`/`flutter build`
    migrator scope, Timeline pre-release versions, and master PR links.
  - Replace `[-<abi>][-<flavor>]` inline code notation that triggered
    `dash_site check-link-references` failures.
- Add dedicated split-per-ABI `versionCode` migration guidance and the
  `-P force-version-code-ignoring-abi=true` escape hatch, with explicit
  `TODO(reidbaker)` blocks for the undecided `flutter/flutter#196561`
  `3.50.x` cherry-pick.
@reidbaker
reidbaker requested a review from mboetger November 16, 2026 21:33
@reidbaker

Copy link
Copy Markdown
Member

@mboetger adding you as an fyi this is not quite ready for review I will take it out of draft when it is ready

@github-actions github-actions Bot removed the d: docs/ flutter/flutter/docs, for contributors label Nov 16, 2026
@reidbaker reidbaker added the CICD Run CI/CD label Nov 16, 2026

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

Left a few comments from an initial review pass (mainly around variant.sources.manifests.all.flatMap failing task-graph resolution when a generated manifest task like GenerateEngineFlagsManifestTask is registered).

(Note: This review was posted by an AI agent on behalf of @bkonyi.)

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 16, 2026
@reidbaker reidbaker added the CICD Run CI/CD label Nov 17, 2026
@reidbaker
reidbaker marked this pull request as ready for review November 17, 2026 02:26
@reidbaker
reidbaker requested a review from a team as a code owner November 17, 2026 02:26

@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 the Flutter Gradle plugin to resolve the base versionCode from the variant's manifest sources when it is not declared in the DSL during --split-per-abi builds. It introduces a new ManifestVersionCodeTask and helper class to parse the manifests, along with corresponding unit and integration tests. The review feedback suggests catching general exceptions rather than only SAXException during manifest parsing to prevent build crashes, and using Gradle's idiomatic providers.fileContents API to safely and lazily read the resolved version code file.

Comment on lines +70 to +72
} catch (e: SAXException) {
return Result.Unresolved("$manifest could not be parsed (${e.message})")
}

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

The DocumentBuilder.parse method can throw both SAXException and IOException. Catching only SAXException means any IOException (or other runtime exceptions) will propagate and crash the Gradle build with a cryptic stack trace. Catching Exception here is safer and ensures that any parsing or reading error is gracefully handled and returned as Result.Unresolved.

Suggested change
} catch (e: SAXException) {
return Result.Unresolved("$manifest could not be parsed (${e.message})")
}
} catch (e: Exception) {
return Result.Unresolved("$manifest could not be parsed (${e.message})")
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

Partially applied. ManifestVersionCodeTaskHelper.readVersionCode now catches IOException alongside SAXException and turns both into actionable build errors (covered by a missing manifest is not found). Kept the catch list narrow rather than catching Exception so unexpected runtime exceptions in Flutter's own code surface with a full stack trace instead of being masked as a manifest parse error.

Comment on lines 730 to 735
return task.flatMap { it.versionCodeFile }.map {
it.asFile
.readText()
.trim()
.toInt()
}

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

Manually reading the file contents using readText() inside a provider map can lead to issues if the provider is queried prematurely (e.g., during configuration time by other plugins or build scripts), throwing a FileNotFoundException. Using Gradle's idiomatic providers.fileContents API is much safer and more robust. It lazily reads the file contents and is fully compatible with Gradle's configuration caching and lazy configuration model.

            return project.providers.fileContents(task.flatMap { it.versionCodeFile }).asText.map {
                it.trim().toInt()
            }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Declined, because switching to providers.fileContents(...) drops the task dependency on ManifestVersionCodeTask. Verified with a ProjectBuilder test:

  • Wiring task.flatMap { it.versionCodeFile }.map { it.asFile.readText() } into a consumer's input preserves the task dependency ([produce]). Querying it before :produce runs throws InvalidUserCodeException: Querying the mapped value of ... before task ':produce' has completed is not supported, not an opaque FileNotFoundException.
  • Wiring providers.fileContents(task.flatMap { it.versionCodeFile }).asText into a consumer's input drops the task dependency ([]). AGP's manifest task wouldn't wait for ManifestVersionCodeTask to run, and an early query silently evaluates to absent.

Kept task.flatMap { it.versionCodeFile }.map { ... } and documented this rule in gradle/AGENTS.md Rule 3.

* other tasks (with `addGeneratedManifestFile`, as Flutter's engine flags manifest is). Gradle
* cannot query a provider derived from those files before the task graph runs.
*/
@DisableCachingByDefault(because = "Reading a few small files is faster than the build cache")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"Reading a few small files is faster than the build cache" what is the evidance this is true. In general I trust gradles abiliy to cache over custom caching rules.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

I didn't have benchmarks backing that claim. Switched ManifestVersionCodeTask to @CacheableTask with a single @InputFile annotated with @PathSensitive(PathSensitivity.RELATIVE) (per gradle/AGENTS.md Rule 5), so cache hits work across machines and checkouts. variantName is marked @Internal since it's only used in the failure message and Gradle never caches failed tasks, allowing variants that share the same main manifest to share a cache entry.

* The `android:versionCode` of [variant]'s manifest sources, read by a
* [ManifestVersionCodeTask] that fails if it cannot be resolved.
*/
private fun manifestVersionCode(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the correct file for this function to live long term? Should this logic live in the helper?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

Moved to tasks/ManifestVersionCodeTaskHelper.kt (replacing top-level ManifestVersionCode.kt), matching the existing EnableHcppManifestTask / EnableHcppManifestTaskHelper split where the task stays thin and the helper owns registration and XML parsing. ManifestVersionCodeTaskHelper.registerTask(project, variant) now registers the task and returns the Provider<Int>, leaving FlutterPlugin.configureSplitPerAbiVersionCodes to choose between the DSL value and the manifest fallback.

variantName.set(variant.name)
versionCodeFile.set(
project.layout.buildDirectory.file(
"intermediates/flutter_manifest_version_code/${variant.name}/version_code.txt"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a string based file path that depends on androids implementation. Is there a type safe way we can get this value? If not why is this safe to add?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

This path doesn't come from AGP. It's an internal output file written only by ManifestVersionCodeTask and read only by our own provider in ManifestVersionCodeTaskHelper.registerTask; AGP never touches the file and only receives the parsed Int on output.versionCode.

  • Why not variant.artifacts? AGP's variant.artifacts API is closed to AGP's own Artifact types, so there isn't a typed AGP artifact slot for a Flutter-internal intermediate file.
  • Why this path is safe: It follows the same scratch-output pattern FGP already uses for GenerateEngineFlagsManifestTask and FlutterTask's intermediateDir, and now uses FlutterPluginConstants.INTERMEDIATES_DIR. Consumers read the file via task.flatMap { it.versionCodeFile } rather than reconstructing the path string, so nothing outside registerTask depends on the layout.
  • Why not intermediates/flutter/<variant>/? FlutterTask declares that directory as its @OutputDirectory, and overlapping task outputs disable Gradle build caching. Giving flutter_manifest_version_code/<variant>/version_code.txt its own subdirectory keeps both tasks cacheable.

)
)
}
// The task output carries the task dependency, so AGP's manifest task runs after it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

That comment was too terse. What it meant: returning task.flatMap { it.versionCodeFile }.map { ... } preserves the Gradle task dependency on ManifestVersionCodeTask. When we pass that provider to output.versionCode, AGP's processManifest task consumes it as an input, so Gradle knows to run ManifestVersionCodeTask before processManifest. Rewrote the comment in ManifestVersionCodeTaskHelper.registerTask to spell that out directly.

fun from(manifests: List<Pair<String, ByteArray?>>): Result {
val factory = DocumentBuilderFactory.newInstance()
factory.isNamespaceAware = true
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does this feature do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

http://apache.org/xml/features/disallow-doctype-decl makes DocumentBuilder reject any XML input containing a <!DOCTYPE ...> declaration. Without it, DocumentBuilderFactory expands DTD entities by default, which allows XML external entity (XXE) file/URL reads (for example <!ENTITY x SYSTEM "file:///etc/passwd">) and recursive entity-expansion bombs ("billion laughs"). Disabling DOCTYPE is OWASP's primary hardening guidance for Java's DocumentBuilderFactory, and Android manifests never use DOCTYPE. Clarified the inline comment in ManifestVersionCodeTaskHelper.parse and added a unit test.

* `android:versionCode` with `tools:remove`, or sets `tools:node="replace"` or
* `tools:node="strict"` on its root element.
*/
fun from(manifests: List<Pair<String, ByteArray?>>): Result {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method is kind of hard to follow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

Agreed. Now that we match AGP and read only the main manifest instead of simulating overlay merging, ManifestVersionCodeTaskHelper.readVersionCode parses a single file's <manifest> root and checks android:versionCode in one flat when block: missing → non-integer → non-positive (<= 0) → Result.Found(versionCode).

Comment on lines +100 to +103
/**
* Whether [root]'s `tools:remove` lists `android:versionCode`, under any prefix bound to the
* Android namespace.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you give me an example of what this looks like in practice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

That KDoc was for removesVersionCode, which handled an overlay manifest binding the Android namespace to a custom prefix inside tools:remove, like:

<!-- src/release/AndroidManifest.xml -->
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:remove="a:versionCode">

removesVersionCode is deleted now because AGP ignores overlays when resolving the variant's versionCode and reads only the main manifest. The only namespace handling left is isNamespaceAware = true + getAttributeNS(ANDROID_NAMESPACE, "versionCode"), so a main manifest with a custom prefix like <manifest xmlns:a="http://schemas.android.com/apk/res/android" a:versionCode="7"> still resolves to 7 (covered by unit test).

Comment on lines +106 to +109
val prefix = name.trim().substringBefore(':', missingDelimiterValue = "")
name.trim().substringAfter(':') == "versionCode" &&
prefix.isNotEmpty() &&
root.lookupNamespaceURI(prefix) == ANDROID_NAMESPACE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels really fragile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

Agreed, deleted removesVersionCode altogether. Splitting tools:remove strings by namespace prefix was only needed to simulate overlay manifest merging. Since AGP only reads versionCode from the main manifest, we don't need any tools: parsing at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test in this file is a bit hard to follow can you make it easier for maintainers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7233196.

Refactored the new manifest-fallback tests into group('versionCode set only in AndroidManifest.xml') and replaced the four-flag helper with small, descriptive steps so each test reads top-to-bottom (_removeDslVersionCode, _addManifestAttributes(appDir, 'debug', ...), _addGradleProperties, _buildSplitPerAbiApks, _expectSplitApkVersionCodes(appDir, build, base: 7)). Left the pre-existing _assertSplitPerAbiVersionCodes tests untouched to keep the diff scoped to this change; happy to clean those up in a follow-up PR if you'd like.

- Read the manifests in ManifestVersionCodeTask instead of a flatMap over
  ManifestFiles.all. The flatMap failed task graph resolution when a task
  generates a manifest, such as -Pflutter.engineShellArgs.
- Use the main manifest's integer versionCode when it has one, as AGP
  injects it over overlays. Otherwise the highest-priority manifest wins.
- Parse manifests from bytes (BOM, encoding), silence Xerces stderr, and
  treat tools:node=replace/strict as unresolved only when the manifest
  declares no versionCode itself.
- Fold the generated-manifest and debug-overlay cases into one integration
  case and drop the duplicate enableLegacyApi=false case.
Scaled by the local macOS run, where the 3 manifest cases added 56s to the
105s of the 4 existing cases.
…ache the task

AGP 9.3.1 reads a variant's DSL-less versionCode only from the main source set's
manifest, and injects it into the merged manifest only when it is positive.
Match that instead of simulating overlay merging, which removes the tools:remove,
tools:node, and namespace-prefix handling. A versionCode of 0 or less now fails
the build with the same actionable message.

- Move ManifestVersionCode into tasks/ManifestVersionCodeTaskHelper, which also
  registers the task, following the EnableHcppManifestTaskHelper pattern.
- Make ManifestVersionCodeTask @CacheableTask with one RELATIVE @InputFile.
- Catch IOException next to SAXException.
- Restore the GradleException and assertTrue imports in FlutterPluginTest that
  the rebase onto flutter#196465 dropped.
- Restructure the new split-per-abi integration tests into a group of linear
  tests with small named helpers.
- Add gradle/AGENTS.md rules for task-produced variant sources.
@reidbaker
reidbaker force-pushed the vcfix-manifest-fallback branch from 95904cc to 7233196 Compare November 17, 2026 03:26
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 17, 2026
@reidbaker reidbaker added the CICD Run CI/CD label Nov 17, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 18, 2026
@reidbaker reidbaker added the CICD Run CI/CD label Nov 18, 2026
reidbaker
reidbaker previously approved these changes Nov 18, 2026
@reidbaker
reidbaker requested review from bkonyi and mboetger November 18, 2026 19:33
…back

# Conflicts:
#	packages/flutter_tools/gradle/src/main/kotlin/FlutterPlugin.kt
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 18, 2026
@reidbaker reidbaker added the CICD Run CI/CD label Nov 18, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 18, 2026
@reidbaker reidbaker added the CICD Run CI/CD label Nov 18, 2026
@reidbaker
reidbaker added this pull request to the merge queue Nov 18, 2026
Merged via the queue into flutter:master with commit a61f510 Nov 18, 2026
21 of 22 checks passed
@reidbaker
reidbaker deleted the vcfix-manifest-fallback branch November 18, 2026 21:28
auto-submit Bot pushed a commit that referenced this pull request Nov 18, 2026
…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`.
reidbaker pushed a commit to reidbaker-agent/flutter that referenced this pull request Nov 18, 2026
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.
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`).
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 19, 2026
flutter/flutter@06f32f8...e8cc6f3

2026-11-19 [email protected] Roll Skia from 280e0965687d to 3dfb69d709c7 (1 revision) (flutter/flutter#196970)
2026-11-19 [email protected] Update outdated `_formattedValues` documentation (flutter/flutter#195765)
2026-11-19 [email protected] [Impeller] Fix Vulkan GPU frame time metrics in benchmarks (flutter/flutter#196339)
2026-11-19 [email protected] Windows: Enable D3D11 multithread protection on ANGLE's device (flutter/flutter#196897)
2026-11-19 [email protected] Roll Skia from 7356c7627e87 to 280e0965687d (1 revision) (flutter/flutter#196957)
2026-11-19 [email protected] Roll Dart SDK from 091f346ad95c to d8d40cf9c21b (2 revisions) (flutter/flutter#196949)
2026-11-19 [email protected] Roll Skia from 73b9219fd1fa to 7356c7627e87 (4 revisions) (flutter/flutter#196951)
2026-11-19 [email protected] Roll Skia from 7bca23228537 to 73b9219fd1fa (1 revision) (flutter/flutter#196948)
2026-11-19 [email protected] [libimpeller] Fix swapped x and y glyph coordinates (flutter/flutter#196552)
2026-11-19 [email protected] [ios][spm]When using cocoapods plugin, give instruction that plugins may just need update (flutter/flutter#195853)
2026-11-19 [email protected] [web] Let the browser handle Control+wheel zoom outside of macOS (flutter/flutter#193362)
2026-11-19 [email protected] Fix focus violation when canRequestFocus set to false for all siblings in same build (flutter/flutter#191536)
2026-11-19 [email protected] Roll Skia from 9fc4f9e23d56 to 7bca23228537 (10 revisions) (flutter/flutter#196941)
2026-11-19 [email protected] Roll Dart SDK from 753488ede427 to 091f346ad95c (2 revisions) (flutter/flutter#196940)
2026-11-19 [email protected] iOS: Convert platform views to points with the frame's pixel ratio (flutter/flutter#196858)
2026-11-19 [email protected] [engine] Defer default font manager resolution to first use for platforms that have a prefetching API only (flutter/flutter#196377)
2026-11-18 [email protected] [flutter_tools] Add example app to package template and decouple platform configurations (flutter/flutter#192441)
2026-11-18 [email protected] [flutter_tools] Rebuild asset bundle when generated manifest content changes (flutter/flutter#191638)
2026-11-18 [email protected] Roll Skia from b11d69796f71 to 9fc4f9e23d56 (2 revisions) (flutter/flutter#196909)
2026-11-18 [email protected] [flutter_tools] Bump cupertino_icons to ^2.0.0 in app and module templates (flutter/flutter#196828)
2026-11-18 [email protected] Update iOS plugin language instructions (flutter/flutter#196614)
2026-11-18 [email protected] iOS: Add tests for rounded rect clips with per-corner/elliptical radii (flutter/flutter#196854)
2026-11-18 [email protected] Revert: [flutter_tools] Migrate lib/runner.dart off runInContext and overrides (flutter/flutter#196926)
2026-11-18 [email protected] Revert: Move macOS desktop builds to ThinLTO (flutter/flutter#196917)
2026-11-18 [email protected] [FGP] Offset split-APK versionCodes from a manifest-only versionCode (flutter/flutter#196561)
2026-11-18 [email protected] [flutter_tools] Migrate lib/runner.dart off runInContext and overrides (flutter/flutter#196387)
2026-11-18 [email protected] docs: remove broken image references from dev/snippets/README.md (flutter/flutter#195587)
2026-11-18 [email protected] Remove the FGP AGP-public-API migration coordination docs (flutter/flutter#196733)
2026-11-18 [email protected] [web] Skip stale safeBlur focus transfer when the element was refocused (flutter/flutter#196550)
2026-11-18 [email protected] Roll Skia from 81ee7327e81c to b11d69796f71 (4 revisions) (flutter/flutter#196900)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
jose-pr pushed a commit to Boriken-Dev/flutter that referenced this pull request Nov 23, 2026
…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`.
@jmagman jmagman mentioned this pull request Nov 23, 2026
10 of 11 tasks
Gustl22 pushed a commit to Gustl22/flutter that referenced this pull request Nov 24, 2026
Reran `dart dev/bots/update_tool_test_durations.dart` added in
flutter#195628. The weights were last
sampled a few weeks ago and tests have changed since. For example
flutter#196561 took
`flutter_build_apk_split_per_abi_test.dart` from 263 to 412 seconds on
Linux.

With the old weights the seven Linux tool_integration_tests shards get
13.5 to 16.8 minutes of tests under the new durations, the ten Mac
shards 11.6 to 13.6, and the fifteen Windows shards 9.4 to 12.5. The new
weights even those out.

The script now samples 10 builds per subshard by default, up from 3. On
Linux, 15 files differed by at least 10 seconds and 10% between a
3-build and a 10-build sample.

Also the script threw `No web builders found for macos` because `Mac
web_tool_tests_1` and `_2` no longer have the shard total in their names
as of flutter#196276. The web and
commands regex now accept names with or without it.

## 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].
- [ ] 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] --split-per-abi gives every split APK the same versionCode when versionCode is set only in AndroidManifest.xml (3.50 regression)

4 participants