@@ -27,23 +27,45 @@ def shouldSplit = !alphaBuild
2727def isWebsiteDegoogled = project. hasProperty(" websiteDegoogled" ) &&
2828 project. property(" websiteDegoogled" ). toString(). toBoolean()
2929
30- // add google-services.json only for play/website builds
30+ // add google-services.json only for play/website builds.
31+ // local dev : copy from the sibling ../firebase/{debug,release} dir (gitignored, outside repo).
32+ // CI : secret is written to app/src/<buildType>/google-services.json
33+ // by the GitHub Actions; so no local copy is needed there.
3134if (! deGoogled) {
3235 def isRelease = gradle. startParameter. taskNames. any {
3336 it. toLowerCase(). contains(" release" )
3437 }
38+ def buildTypeName = isRelease ? " release" : " debug"
3539
36- def sourceFile = file(isRelease
37- ? " ${ rootDir.parent} /firebase/release/google-services.json"
38- : " ${ rootDir.parent} /firebase/debug/google-services.json" )
39-
40+ def sourceFile = file(" ${ rootDir.parent} /firebase/${ buildTypeName} /google-services.json" )
4041 def targetFile = file(" ${ projectDir} /google-services.json" )
4142
4243 if (sourceFile. exists()) {
44+ // local dev: place the file at the module root so all variants pick it up
4345 targetFile. parentFile. mkdirs()
4446 targetFile. bytes = sourceFile. bytes
47+ logger. lifecycle(" google-services.json: copied from ${ sourceFile} " )
48+ } else if (targetFile. exists()) {
49+ // already in place (manual placement or a prior local copy); keep as-is
50+ logger. lifecycle(" google-services.json: using existing ${ targetFile} " )
4551 } else {
46- throw new GradleException (" Missing ${ sourceFile} " )
52+ // no local copy available; verify a variant source-set file exists so the
53+ // google-services plugin can resolve it (the CI secret path). Fail with a
54+ // helpful message only if nothing is resolvable anywhere.
55+ def srcDir = file(" src" )
56+ def hasSrcSetFile = srcDir. isDirectory() && (srcDir. listFiles()?. any { dir ->
57+ dir. isDirectory() && new File (dir, " google-services.json" ). exists()
58+ } ?: false )
59+ if (hasSrcSetFile || file(" src/google-services.json" ). exists()) {
60+ logger. lifecycle(" google-services.json: no local copy; deferring to " +
61+ " google-services plugin (variant source-set resolution, e.g. CI)" )
62+ } else {
63+ throw new GradleException (
64+ " google-services.json not found for '${ buildTypeName} ' build.\n " +
65+ " Local dev : place it at ${ sourceFile} \n " +
66+ " (or directly at ${ targetFile} )\n " +
67+ " CI : ensure the secret is written to app/src/google-services.json" )
68+ }
4769 }
4870} else {
4971 logger. info(" skipping google-services.json for de-googled/F-Droid build" )
0 commit comments