play-services-plugins
play-services-plugins copied to clipboard
google_app_id and google_api_key sometimes missing
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:
- Build apk
- Analyze apk
Expected behavior
google_app_id
and google_api_key
should be part of the resources
Desktop (please complete the following information):
- Gradle version: 7.0.2
- Android Studio version : Irrelevant, fails on gradle CLI build
- Plugin name and version [e.g. OSS Licenses 16.0.0]: Google services plugin 4.3.10
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.
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.
If you need a working workaround (Groovy):
afterEvaluate {
mergeDebugResources.mustRunAfter(processDebugGoogleServices)
mergeReleaseResources.mustRunAfter(processReleaseGoogleServices)
}
Maybe not very DRY, but does the job 😄
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)
}
}
}
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)
}
}
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.