Skip to content

feat: upgrade existing Google Services Gradle plugin version on configure - #479

Merged
SelaseKay merged 2 commits into
invertase:mainfrom
AustinBenoit:feat/appcheck-seamless-debug-tokens
Nov 17, 2026
Merged

SelaseKay merged 2 commits into
invertase:mainfrom
AustinBenoit:feat/appcheck-seamless-debug-tokens

Conversation

@AustinBenoit

@AustinBenoit AustinBenoit commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

When users re-run flutterfire configure on an existing Android project whose android/settings.gradle or android/settings.gradle.kts already declares com.google.gms.google-services, the existing version pin (for example 4.3.15 or 4.4.4) was left unchanged. Because flutter pub upgrade does not modify Gradle settings files, projects stayed on older plugin versions that lack newer build-time plugin capabilities.

Changes

  • Adds upgradeGoogleServicesPluginVersion in packages/flutterfire_cli/lib/src/firebase/firebase_android_writes.dart. It moves an existing com.google.gms.google-services pin in android/settings.gradle(.kts) forward, never downgrades it, and rewrites only the text of the version literal.
  • Matches Groovy (id "...", id '...', id("...")) and Kotlin (id("...")) declarations with version "..." or version("..."), whatever the spacing and whether they end in apply false or apply(false). Commented-out declarations are ignored.
  • Prints a warning naming the settings file and the declaration when the plugin is declared but its version is missing or is not a semantic version literal (a version catalog reference, for example).
  • Takes the target version from the firebase_core the app resolves to, read from .dart_tool/package_config.json (pub workspaces included) by the new getResolvedFirebaseCorePubSpec. The Crashlytics and Performance plugin versions use the same lookup. The existing pub cache lookup stays as the fallback when the app's dependencies are not resolved: missing declarations are still added from it, but an existing pin is not rewritten.
  • Runs the upgrade from the settings path of gradleContentUpdates, ahead of applying the plugin, so it still happens when android/app/build.gradle(.kts) contains the legacy com.google.gms:google-services classpath declaration.
  • gradleContentUpdates takes an optional logger, used for the warning.

Testing

  • dart format --output=none --set-exit-if-changed . (no changes)
  • dart analyze --fatal-infos (no issues)
  • dart test test/firebase_android_writes_test.dart (44/44 passed), covering commented-out declarations, apply(false), extra whitespace, unreadable versions, the resolved firebase_core lookup with several versions in a pub cache, and the legacy classpath case for both DSLs.

Type of Change

  • ✨ feat -- New feature (non-breaking change which adds functionality)
  • 🛠️ fix -- Bug fix (non-breaking change which fixes an issue)
  • ❌ ! -- Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 refactor -- Code refactor
  • ✅ ci -- Build configuration change
  • 📝 docs -- Documentation
  • 🗑️ chore -- Chore

Prepared with AI coding agents (Google-internal, built on Jetski) and opened by @AustinBenoit.

…gure

Update `_applyGoogleServicesPlugin` and `_applyGoogleServicesPluginKts` to
upgrade older `com.google.gms.google-services` plugin pins forward to
`googleServicesGradlePluginVersion` when re-running `flutterfire configure`.
@CLAassistant

CLAassistant commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Hi @AustinBenoit, thanks for the PR. I went through the implementation and found a few edge cases worth addressing.

1. Comments can prevent the actual plugin version from being upgraded

upgradeGoogleServicesPluginVersion currently uses the first matching declaration in the file. However, that match could be inside a comment.

For example, assuming the target version is 4.7.0:

// id "com.google.gms.google-services" version "4.7.0" apply false
id "com.google.gms.google-services" version "4.3.15" apply false

The helper finds 4.7.0 in the comment, considers the version up to date, and returns without upgrading the actual declaration (4.3.15).

If the commented version is older than the target, the helper could instead end up updating the comment rather than the actual declaration.

Could we ensure that commented-out declarations are ignored and that the helper finds the actual plugin declaration before deciding whether an upgrade is needed?

2. Some valid Gradle declarations are detected but not upgraded

The plugin existence check and the version matching check don't currently accept the same syntax.

For example, in android/settings.gradle.kts:

id("com.google.gms.google-services") version "4.3.15" apply(false)

The Kotlin existence check recognises the plugin ID, so no new declaration is added. However, the version matching regex expects apply false, so it doesn't recognise this declaration either.

The same issue occurs with extra whitespace or tabs in the Groovy settings.gradle declaration.

As a result, flutterfire configure completes successfully without upgrading the version.

Could we make the version matching handle these valid syntax variations? Also, if the plugin ID is present but its version cannot be parsed, it would be helpful to print a warning identifying the file and the declaration that couldn't be processed.

3. The target version should come from the current app's resolved firebase_core dependency

Currently, the target version comes from:

getFirebaseCorePubSpec().googleServicesGradlePluginVersion

getFirebaseCorePubSpec() selects the highest firebase_core version available in the local pub cache, rather than the version resolved by the current application.

For example, an app using firebase_core 3.10.0 could end up using the Google Services Gradle plugin version from firebase_core 3.15.0 simply because that version is also present in the cache. This would happen if those two packages declare different Google Services plugin versions.

Although this lookup already exists, this PR passes its result into the new upgrade. That upgrade runs when flutterfire configure takes the latest settings path and the plugin is already declared. On that path, another project's cached firebase_core can change the current project's pin.

Could we instead resolve the version from the firebase_core dependency used by the current app?

The forward-only comparison should remain so that an existing newer plugin version is never downgraded.

This lookup is also used for the Crashlytics and Performance plugin versions, so it would be worth considering those paths when addressing this.

4. The legacy classpath check skips the settings.gradle upgrade

_applyGoogleServicesPlugin returns early when android/app/build.gradle contains com.google.gms:google-services. _applyGoogleServicesPluginKts returns early when android/app/build.gradle.kts contains that text. In both functions the settings upgrade is below that return, so the settings file is left unchanged even when its plugin declaration is older than the target.

For example, a project could have the legacy classpath declaration in android/app/build.gradle alongside a plugin declaration in android/settings.gradle.

Could we ensure the settings declaration is still checked and upgraded when this legacy classpath declaration is present?

5. Additional test coverage

I'd suggest adding coverage for the following cases:

  • A commented-out declaration appearing before the actual plugin declaration.
  • A valid apply(false) declaration in Kotlin DSL.
  • Extra whitespace in a Groovy declaration.
  • Selecting the Google Services plugin version from the current app's resolved firebase_core dependency when multiple versions exist in the pub cache.

These should help ensure the upgrade works correctly across existing project configurations.

- Ignore commented-out declarations when looking for the pin.
- Accept `apply(false)`, extra whitespace and parenthesised Groovy
  declarations, and warn when a declaration's version cannot be read.
- Take the target version from the `firebase_core` the app resolves to
  instead of the highest one in the pub cache. The cache lookup stays as
  the fallback for adding missing declarations and never rewrites a pin.
- Upgrade the settings pin even when `android/app/build.gradle(.kts)`
  still has the legacy classpath declaration.
@AustinBenoit

Copy link
Copy Markdown
Contributor Author

Thanks for the review @SelaseKay. All five points are addressed in f95a21f:

  1. Commented-out declarations. Comments (// and /* */) are masked before matching, so only real declarations are compared and rewritten. A // inside a string, such as a repository URL, is not treated as a comment.
  2. Syntax variations. The matcher now accepts apply(false), extra spaces or tabs, and parenthesised Groovy declarations. When the plugin is declared but its version is missing or is not a semantic version literal (a version catalog reference, for example), the CLI prints a warning naming the settings file and the declaration, and leaves it unchanged.
  3. Target version. The version now comes from the firebase_core the app resolves to, read from .dart_tool/package_config.json (pub workspaces included). The Crashlytics and Performance plugin versions use the same lookup. When the app's dependencies are not resolved, the pub cache lookup is still used to add a missing declaration, as before, but an existing pin is not rewritten from it. The forward-only comparison is unchanged.
  4. Legacy classpath. The pin upgrade now runs before the plugin is applied, so the early return for com.google.gms:google-services in android/app/build.gradle(.kts) no longer skips it.
  5. Tests. Added cases for each of the above, including the resolved firebase_core lookup with several versions in a pub cache and the legacy classpath case for both DSLs.

@github-actions github-actions Bot added the Needs Attention OP created or responded to issue and it needs attention. label Nov 13, 2026
@SelaseKay
SelaseKay merged commit 1ff52a0 into invertase:main Nov 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Attention OP created or responded to issue and it needs attention.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants