Skip to content

Migrate the flutter-apk copy and per-ABI versionCode to the variant API - #7

Open
reidbaker-agent wants to merge 1 commit into
agp-assets-onvariantsfrom
agp-apk-copy-versioncode
Open

Migrate the flutter-apk copy and per-ABI versionCode to the variant API#7
reidbaker-agent wants to merge 1 commit into
agp-assets-onvariantsfrom
agp-apk-copy-versioncode

Conversation

@reidbaker-agent

@reidbaker-agent reidbaker-agent commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Phase 7 of 11 of the AGP public-API migration; stacked on #6.

Phase P6 of the AGP public-API migration (flutter#180137,
flutter#166550). The application path no longer uses the legacy
variant API at all:

  • New CopyFlutterApksTask copies the variant's SingleArtifact.APK
    directory contents (via BuiltArtifactsLoader) into
    build/outputs/flutter-apk under the unchanged names
    app[-abi][-flavor]-<build-mode>.apk. It is attached as a finalizer of
    assemble<Variant> (matched by name, with a projectsEvaluated
    assertion that fails loudly if the assemble task was never created,
    instead of silently leaving flutter run/build without APKs). The task
    declares individual predictable @OutputFiles - computed from target
    platforms, flavor, and build mode - rather than the shared
    flutter-apk directory, so it is UP-TO-DATE-capable without
    overlapping outputs between variants; it replaces the old
    assemble.doLast copy.
  • Per-ABI versionCode for --split-per-abi builds is now a read-then-set
    on VariantOutput.versionCode inside onVariants (the output is seeded
    with AGP's merged value, which covers flavor-defined versionCodes),
    replacing versionCodeOverride on the legacy ApkVariantOutput. When
    the built APK's versionCode differs from what Flutter configured
    (e.g. an afterEvaluate mutation), CopyFlutterApksTask logs a warning
    pointing at androidComponents.onVariants.
  • The entire legacy applicationVariants.configureEach block and its
    helpers are deleted; AbstractAppExtension remains only in the
    add-to-app module path, which migrates next.

Verification (CI): split-per-abi + apkanalyzer per-ABI versionCode
assertions including the flavor-defined-versionCode case; flavor
filename check; flutter run / hot restart / attach; Windows-runner
smoke for the copy tasks; android_e2e_api_test; gradle unit tests on
both AGP axes.

Revert-safe until P7 lands (mutually tolerant with P7 until P10).

CI must run the FGP unit tests (the Kotlin suite in packages/flutter_tools/gradle could not run in the delivery sandbox: dl.google.com returns 403, so AGP artifacts do not resolve).

Phase P6 of the AGP public-API migration (flutter#180137,
flutter#166550). The application path no longer uses the legacy
variant API at all:

- New CopyFlutterApksTask copies the variant's SingleArtifact.APK
  directory contents (via BuiltArtifactsLoader) into
  build/outputs/flutter-apk under the unchanged names
  app[-abi][-flavor]-<build-mode>.apk. It is attached as a finalizer of
  assemble<Variant> (matched by name, with a projectsEvaluated
  assertion that fails loudly if the assemble task was never created,
  instead of silently leaving flutter run/build without APKs). The task
  declares individual predictable @OutputFiles - computed from target
  platforms, flavor, and build mode - rather than the shared
  flutter-apk directory, so it is UP-TO-DATE-capable without
  overlapping outputs between variants; it replaces the old
  assemble.doLast copy.
- Per-ABI versionCode for --split-per-abi builds is now a read-then-set
  on VariantOutput.versionCode inside onVariants (the output is seeded
  with AGP's merged value, which covers flavor-defined versionCodes),
  replacing versionCodeOverride on the legacy ApkVariantOutput. When
  the built APK's versionCode differs from what Flutter configured
  (e.g. an afterEvaluate mutation), CopyFlutterApksTask logs a warning
  pointing at androidComponents.onVariants.
  Note on onVariants FIFO callback ordering: Because FGP is applied at
  line 25 of build.gradle.kts, FGP's callback executes before app-level
  onVariants callbacks at line 70. Any custom app-level block reading
  output.versionCode.get() will observe the ABI-offset value. For
  standard apps, no change is needed; monotonic ABI ordering and Play
  Store uniqueness are preserved even if an app transforms versionCode.
- The entire legacy applicationVariants.configureEach block and its
  helpers are deleted; AbstractAppExtension remains only in the
  add-to-app module path, which migrates next.

Verification (CI): split-per-abi + apkanalyzer per-ABI versionCode
assertions including the flavor-defined-versionCode case; flavor
filename check; flutter run / hot restart / attach; Windows-runner
smoke for the copy tasks; android_e2e_api_test; gradle unit tests on
both AGP axes.

Revert-safe until P7 lands (mutually tolerant with P7 until P10).
@reidbaker
reidbaker force-pushed the agp-apk-copy-versioncode branch from b7a23f7 to 53bcc7f Compare July 31, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants