11plugins {
22 id ' com.android.application'
3- // ADFA-4466 Phase 1: Firebase Analytics.
4- id ' com.google.gms.google-services'
3+ // ADFA-4466 Phase 1: Firebase Analytics. The google-services plugin fails the build when
4+ // google-services.json is absent, so it is applied CONDITIONALLY at the bottom of this file
5+ // (present -> Firebase on; absent -> AnalyticsClient compiles out and the build still works).
56}
67
78// 1. AUTO-VERSIONING MAP (Must be defined outside the 'android' block)
@@ -24,6 +25,12 @@ def gitShortSha = {
2425}
2526ext. gitSha = gitShortSha()
2627
28+ // Firebase is OPTIONAL for local/contributor builds. google-services.json holds the real project keys
29+ // and is gitignored, so a fresh clone doesn't have it. When it's absent we skip the google-services
30+ // plugin (which would otherwise fail the build) and flag AnalyticsClient off via BuildConfig so it never
31+ // touches the uninitialized Firebase SDK. Set the file to enable analytics for a release build.
32+ def hasGoogleServices = file(" google-services.json" ). exists()
33+
2734android {
2835 // 2. Identity
2936 namespace ' org.iiab.controller'
@@ -45,6 +52,8 @@ android {
4552 : (project. ext. gitSha ? " -${ project.ext.gitSha} " : " " )
4653 versionName " v0.7.0-beta${ ciSuffix} "
4754 buildConfigField " String" , " GIT_SHA" , " \" ${ project.ext.gitSha} \" "
55+ // True only when google-services.json is present, so AnalyticsClient can compile out cleanly.
56+ buildConfigField " boolean" , " ANALYTICS_ENABLED" , " ${ hasGoogleServices} "
4857
4958 setProperty(" archivesBaseName" , " $applicationId -$versionName " )
5059
@@ -753,3 +762,14 @@ task refreshKolibriCatalog {
753762 }
754763 }
755764}
765+
766+ // ADFA-4466 / build resilience: apply the Firebase google-services plugin only when its config file is
767+ // present. Without it the plugin fails the build; skipping it lets contributors build a working APK with
768+ // analytics compiled out (BuildConfig.ANALYTICS_ENABLED = false). Applied at the bottom, as the plugin
769+ // expects, so it processes the already-configured android block.
770+ if (hasGoogleServices) {
771+ apply plugin : ' com.google.gms.google-services'
772+ logger. lifecycle(" K2Go: google-services.json found — Firebase Analytics enabled." )
773+ } else {
774+ logger. lifecycle(" K2Go: google-services.json not found — building WITHOUT Firebase (analytics disabled)." )
775+ }
0 commit comments