From 69351c171aa0de56f493cb8b03094152e0d5c965 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Fri, 10 Oct 2025 16:13:22 -0400 Subject: [PATCH] Fix CopyGoogleServicesPlugin for dataconnect A recent change to `CopyGoogleServicesPlugin.kt` in https://github.com/firebase/firebase-android-sdk/pull/7454 caused it to skip all of its logic if the project already had its own `google-services.json` (as firebase-dataconnect _does_). Part of this logic is to apply the `com.google.gms.google-services` Gradle plugin when running (or compiling) tests. The `firebase-dataconnect` project relied on this side effect and the changes to `CopyGoogleServicesPlugin.kt` caused this side effect to no longer happen to firebase-dataconnect, causing the following build error: ``` firebase-dataconnect/src/androidTest/kotlin/com/google/firebase/dataconnect/testutil/FirebaseAppIdTestUtil.kt:23:68 Unresolved reference 'string'. ``` The fix in this commit modifies `CopyGoogleServicesPlugin.kt` to apply the `com.google.gms.google-services` Gradle plugin just as it did before, even if the project defines its own `google-services.json`. This was probably the intended behavior all along. --- .../plugins/CopyGoogleServicesPlugin.kt | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/src/main/java/com/google/firebase/gradle/plugins/CopyGoogleServicesPlugin.kt b/plugins/src/main/java/com/google/firebase/gradle/plugins/CopyGoogleServicesPlugin.kt index 603143c84ad..30da937c85b 100644 --- a/plugins/src/main/java/com/google/firebase/gradle/plugins/CopyGoogleServicesPlugin.kt +++ b/plugins/src/main/java/com/google/firebase/gradle/plugins/CopyGoogleServicesPlugin.kt @@ -17,7 +17,6 @@ package com.google.firebase.gradle.plugins import com.android.build.gradle.BaseExtension -import com.android.build.gradle.internal.tasks.factory.dependsOn import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project @@ -38,18 +37,17 @@ import org.gradle.kotlin.dsl.register abstract class CopyGoogleServicesPlugin : Plugin { override fun apply(project: Project) { if (File(project.projectDir, "google-services.json").exists()) { - project.logger.warn("Google Services file already present in project, skipping copy task") - return - } - - val sourcePath = getSourcePath(project) - val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project, sourcePath) - - project.allprojects { - // fixes dependencies with gradle tasks that do not properly dependOn `preBuild` - tasks.configureEach { - if (name !== "copyRootGoogleServices") { - dependsOn(copyRootGoogleServices) + project.logger.info("Google Services file already present in project, skipping copy task") + } else { + val sourcePath = getSourcePath(project) + val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project, sourcePath) + + project.allprojects { + // fixes dependencies with gradle tasks that do not properly dependOn `preBuild` + tasks.configureEach { + if (name !== "copyRootGoogleServices") { + dependsOn(copyRootGoogleServices) + } } } }