diff --git a/android/build.gradle b/android/build.gradle index 26d6a3914f..aa66557327 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,19 +5,42 @@ buildscript { jcenter() } - ext.googleServiceEnabled = file('google-services.json').exists() - if (googleServiceEnabled) { - println("Building with Google Services") - } else { - println("Building without Google Services") - } + // + // The magic below is needed to disable Google Mobile Services (a.k.a GMS) and + // Google Firebase Services during the build time. Unfortunately, the only way + // to disable Gradle plugins is to add these hardcore switches to buildscript(). + // + + // Detect flavors from the task name. + def isFdroid = getGradle().getStartParameter().getTaskRequests().toString().toLowerCase().contains("fdroid"); + def isBeta = getGradle().getStartParameter().getTaskRequests().toString().toLowerCase().contains("beta"); + + // Enable Google Mobile Services for all flavors except fdroid. + def googleMobileServicesDefault = !isFdroid; + // Add a parameter to force GMS. + ext.googleMobileServicesEnabled = project.hasProperty('gms') ?: googleMobileServicesDefault; + + // Enable Firebase for all beta flavors except fdroid only if google-services.json exists. + def googleFirebaseServicesDefault = isBeta && !isFdroid && file('google-services.json').exists(); + // Add a parameter to force Firebase. + ext.googleFirebaseServicesEnabled = project.hasProperty('firebase') ?: googleFirebaseServicesDefault; dependencies { classpath 'com.android.tools.build:gradle:4.1.2' - if (googleServiceEnabled) { + + if (googleMobileServicesEnabled) { + println("Building with Google Mobile Services") classpath 'com.google.gms:google-services:4.3.5' + } else { + println("Building without Google Services") + } + + if (googleFirebaseServicesEnabled) { + println("Building with Google Firebase Services") classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.1' classpath 'com.google.firebase:firebase-appdistribution-gradle:2.1.0' + } else { + println("Building without Google Firebase Services") } } } @@ -45,8 +68,10 @@ repositories { apply plugin: 'com.android.application' apply from: 'secure.properties' -if (googleServiceEnabled) { +if (googleMobileServicesEnabled) { apply plugin: 'com.google.gms.google-services' +} +if (googleFirebaseServicesEnabled) { apply plugin: 'com.google.firebase.crashlytics' apply plugin: 'com.google.firebase.appdistribution' } @@ -57,10 +82,13 @@ dependencies { implementation 'androidx.multidex:multidex:' + propMultiDexVersion - // Google Services - if (googleServiceEnabled) { + // Google Mobile Services + if (googleMobileServicesEnabled) { implementation 'com.google.android.gms:play-services-location:17.0.0' - implementation 'com.google.firebase:firebase-analytics:17.4.4' + } + + // Google Firebase Services + if (googleFirebaseServicesEnabled) { implementation 'com.google.firebase:firebase-crashlytics:17.1.1' implementation 'com.google.firebase:firebase-crashlytics-ndk:17.1.1' } @@ -227,10 +255,15 @@ android { manifest.srcFile 'AndroidManifest.xml' res.srcDirs = ['res'] java.srcDirs = ['src'] - if (googleServiceEnabled) { - java.srcDirs += 'flavors/google-services-enabled' + if (googleMobileServicesEnabled) { + java.srcDirs += 'flavors/gms-enabled' } else { - java.srcDirs += 'flavors/google-services-disabled' + java.srcDirs += 'flavors/gms-disabled' + } + if (googleFirebaseServicesEnabled) { + java.srcDirs += 'flavors/firebase-enabled' + } else { + java.srcDirs += 'flavors/firebase-disabled' } // assets folder is auto-generated by tools/android/update_assets.sh, so we keep all static resources in separate folders. @@ -456,7 +489,7 @@ android { resValue 'string', 'app_id', android.defaultConfig.applicationId resValue 'string', 'app_name', project.ext.appName ndk.debugSymbolLevel = 'SYMBOL_TABLE' - if (googleServiceEnabled) { + if (googleFirebaseServicesEnabled) { firebaseCrashlytics { nativeSymbolUploadEnabled true } @@ -471,7 +504,7 @@ android { resValue 'string', 'app_id', android.defaultConfig.applicationId + applicationIdSuffix resValue 'string', 'app_name', project.ext.appName + applicationIdSuffix ndk.debugSymbolLevel = 'SYMBOL_TABLE' - if (googleServiceEnabled) { + if (googleFirebaseServicesEnabled) { firebaseCrashlytics { nativeSymbolUploadEnabled true } diff --git a/android/flavors/google-services-disabled/com/mapswithme/util/CrashlyticsUtils.java b/android/flavors/firebase-disabled/com/mapswithme/util/CrashlyticsUtils.java similarity index 100% rename from android/flavors/google-services-disabled/com/mapswithme/util/CrashlyticsUtils.java rename to android/flavors/firebase-disabled/com/mapswithme/util/CrashlyticsUtils.java diff --git a/android/flavors/google-services-enabled/com/mapswithme/util/CrashlyticsUtils.java b/android/flavors/firebase-enabled/com/mapswithme/util/CrashlyticsUtils.java similarity index 100% rename from android/flavors/google-services-enabled/com/mapswithme/util/CrashlyticsUtils.java rename to android/flavors/firebase-enabled/com/mapswithme/util/CrashlyticsUtils.java diff --git a/android/flavors/google-services-disabled/com/mapswithme/maps/location/LocationProviderFactory.java b/android/flavors/gms-disabled/com/mapswithme/maps/location/LocationProviderFactory.java similarity index 100% rename from android/flavors/google-services-disabled/com/mapswithme/maps/location/LocationProviderFactory.java rename to android/flavors/gms-disabled/com/mapswithme/maps/location/LocationProviderFactory.java diff --git a/android/flavors/google-services-enabled/AndroidManifest.xml b/android/flavors/gms-enabled/AndroidManifest.xml similarity index 100% rename from android/flavors/google-services-enabled/AndroidManifest.xml rename to android/flavors/gms-enabled/AndroidManifest.xml diff --git a/android/flavors/google-services-enabled/com/mapswithme/maps/location/GoogleFusedLocationProvider.java b/android/flavors/gms-enabled/com/mapswithme/maps/location/GoogleFusedLocationProvider.java similarity index 100% rename from android/flavors/google-services-enabled/com/mapswithme/maps/location/GoogleFusedLocationProvider.java rename to android/flavors/gms-enabled/com/mapswithme/maps/location/GoogleFusedLocationProvider.java diff --git a/android/flavors/google-services-enabled/com/mapswithme/maps/location/LocationProviderFactory.java b/android/flavors/gms-enabled/com/mapswithme/maps/location/LocationProviderFactory.java similarity index 100% rename from android/flavors/google-services-enabled/com/mapswithme/maps/location/LocationProviderFactory.java rename to android/flavors/gms-enabled/com/mapswithme/maps/location/LocationProviderFactory.java