google / play-services-plugins

Plugins to help with using Google Play services SDK.
https://developers.google.com/android/guides/overview
Apache License 2.0
471 stars 138 forks source link

google_app_id and google_api_key sometimes missing #210

Closed auras closed 7 months ago

auras commented 2 years ago

Describe the bug After updating to 4.3.10 our builds sometimes are missing some fields like google_app_id and google_api_key. There's no indication of a build problem (I would expect a build fail) during the build process only when starting the app and noticing that firebase is crashing because the google_app_id is missing.

It only happens on some builds, on our CI, and those builds are from the command line. It happens both for debug and release builds.

To Reproduce Steps to reproduce the behavior:

  1. Build apk
  2. Analyze apk

Expected behavior google_app_id and google_api_key should be part of the resources

Desktop (please complete the following information):

Additional context

I noticed this message during the build when it happend:

> Task :app:mergeBonialReleaseResources
Execution optimizations have been disabled for task ':app:mergeBonialReleaseResources' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '/bitrise/src/app/build/generated/res/google-services/bonial/release'. Reason: Task ':app:mergeBonialReleaseResources' uses this output of task ':app:processBonialReleaseGoogleServices' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
> Task :app:processBonialReleaseGoogleServices
Execution optimizations have been disabled for task ':app:processBonialReleaseGoogleServices' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '/bitrise/src/app/build/generated/res/google-services/bonial/release'. Reason: Task ':app:mergeBonialReleaseResources' uses this output of task ':app:processBonialReleaseGoogleServices' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
tprochazka commented 2 years ago

We have the same issue, but it happens very rarely and randomly.

But I think that solution is clear, not?

Gradle detected a problem with the following location: '/home/tcagent/.buildAgent/work/master/cleaner/app/build/generated/res/google-services/defaultBackendTest/debug'. Reason: Task ':app:mergeDefaultBackendTestDebugResources' uses this output of task ':app:processDefaultBackendTestDebugGoogleServices' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.3/userguide/validation_problems.html#implicit_dependency for more details about this problem

So should be enough to declare dependency between mergeResources and processGoogleServices, to be sure, that order of it will be always deterministic, now it is somehow random.

Maybe using org.gradle.parallel=false would solve it, but it will probably also increase the build time. I did not try it.

ILikeYourHat commented 2 years ago

If you need a working workaround (Groovy):

afterEvaluate {
    mergeDebugResources.mustRunAfter(processDebugGoogleServices)
    mergeReleaseResources.mustRunAfter(processReleaseGoogleServices)
}

Maybe not very DRY, but does the job 😄

choongyouqi commented 2 years ago

a kotlin dsl version that works with multiple buildTypes and productFlavors

afterEvaluate {
    val buildTypes = android.buildTypes.map { it.name.capitalize() }
    val productFlavors = android.productFlavors.map { it.name.capitalize() }
    productFlavors.forEach { productFlavor ->
        buildTypes.forEach { buildType ->
            val processGoogleServicesTask = tasks
                .findByName("process${productFlavor}${buildType}GoogleServices") ?: error("googleTask not found")
            val mergeResourcesTask = tasks
                .findByName("merge${productFlavor}${buildType}Resources") ?: error("mergeTask not found")
            mergeResourcesTask.mustRunAfter(processGoogleServicesTask)
        }
    }
}
AndreasBoehm commented 2 years ago

Below a Groovy version that works with multiple buildTypes and productFlavors

project.afterEvaluate {
    android.applicationVariants.all { variant ->
        logger.trace("variant.name: ${variant.name}")

        def googleServicesTask = tasks.findByName("process${variant.name.capitalize()}GoogleServices")

        variant.mergeResources.mustRunAfter(googleServicesTask)
    }
}
mannodermaus commented 2 years ago

After updating to Google services plugin 4.3.13, I made a handful of test compilations and I don't think this happens anymore. The release notes for 4.3.12 point to "improved compatibility with AGP 7.1+" (#180), so maybe this is resolved with that PR.