79780008

Date: 2025-10-01 12:02:26
Score: 0.5
Natty:
Report link

Applying a plugin in afterEvaluate {...} or androidComponents {...} results in compilation error as it is too late to apply plugins in those blocks.

To check the active variant, we can query the tasks specific to our build and see if it contains its flavor name:

/**
 * Applies the Google Services plugin only if the build flavor is "fdroid",
 * determined by inspecting the Gradle task names.
 */
val tasks = gradle.startParameter.taskNames
if (tasks.any { it.contains("fdroid", ignoreCase = true).not() }) {
    pluginManager.apply(libs.plugins.google.services.get().pluginId)
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Roozbeh Zarei