From bc72c43259f8d043bb0e89842e459348ffb1174c Mon Sep 17 00:00:00 2001 From: Gino Miceli <228050+gino-m@users.noreply.github.com> Date: Thu, 2 Nov 2023 20:14:09 +0200 Subject: [PATCH] Add per-deployment flavors to ensure correct backend is used (#2036) * Clean up config, add flavors * Fix for local emu * Fix CI build --- .gitignore | 5 ---- CONTRIBUTING.md | 34 ++++++------------------- ground/build.gradle | 24 +++++++++++------ ground/google-services.json | 51 ------------------------------------- sharedTest/build.gradle | 6 +++++ 5 files changed, 30 insertions(+), 90 deletions(-) delete mode 100644 ground/google-services.json diff --git a/.gitignore b/.gitignore index 2e4365c226..38df241ab8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,7 @@ .* !.gitignore !gradle/ -**/google_maps_api.xml **/google-services.json -**/secrets.properties - -# Blank config. Needed for Cloud builds. -!ground/google-services.json # Taken from Android.gitignore https://github.com/github/gitignore/blob/master/Android.gitignore # diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b57312f688..ce89b849b9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -138,41 +138,23 @@ either the commit message for your changes or in your pull request. ### Add Google Maps API Key(s) -If you do not have them, generate *release* and *debug* Google Maps API keys by -following the instructions at: - - https://developers.google.com/maps/documentation/android-api/signup. - -Edit or create `ground/secrets.properties` and set the `GOOGLE_MAPS_API_KEY` property to your API key. -``` - GOOGLE_MAPS_API_KEY=AIbzvW8e0ub... -``` - -Verify the SHA-1 certificate fingerprint described in the API key generation instructions is -registered with package name `com.google.android.ground`. To check, visit - -https://console.cloud.google.com/apis/credentials - -To view the SHA-1 of the debug key generated by Android Studio run: - -``` -$ keytool -list -v -keystore "$HOME/.android/debug.keystore" -alias androiddebugkey -storepass android -keypass android -``` - ### Set up Firebase 1. Create a new Firebase project at: https://console.firebase.google.com/ -2. Save config file for Android app to `ground/src/debug/google-services.json`: +2. Add a new Android app with package name `com.google.android.ground`. - https://support.google.com/firebase/answer/7015592 +3. Add the debug SHA-1 of your device. -This includes the API key and URL for your new Firebase project. + To view the SHA-1 of the debug key generated by Android Studio run: -**Note:** Do not overwrite `ground/google-services.json`, this is used with Google Cloud build and should be left as-is. + ``` + $ keytool -list -v -keystore "$HOME/.android/debug.keystore" -alias androiddebugkey -storepass android -keypass android + ``` +4. Download the config file for the Android app to `ground/src/debug/google-services.json` ### Set up Google Cloud Build (optional) @@ -201,7 +183,7 @@ $ cd cloud-builder $ gcloud builds submit --config=cloudbuild.yaml --substitutions=_ANDROID_VERSION=30 ``` -5. Ensure that the docker image is uploaded under "Container Registry" in cloud project +5. Ensure that the Docker image is uploaded under "Container Registry" in cloud project ### Troubleshooting diff --git a/ground/build.gradle b/ground/build.gradle index d4e14fced2..dd7eb793da 100644 --- a/ground/build.gradle +++ b/ground/build.gradle @@ -40,13 +40,11 @@ project.ext { coroutinesVersion = "1.6.4" } -// Load secrets.properties -def secretsFile = file('secrets.properties') -def secrets = new Properties() -if (secretsFile.exists()) { - secrets.load(new FileInputStream(secretsFile)) -} -def googleMapsApiKey = secrets.getProperty('GOOGLE_MAPS_API_KEY', '') +// Extract API key from google-services.json for use with Google Maps SDK. +import groovy.json.JsonSlurper +def inputFile = new File("ground/src/debug/google-services.json") +def json = inputFile.exists() ? new JsonSlurper().parseText(inputFile.text) : null +def googleMapsApiKey = json ? json.client[0].api_key[0].current_key : '' def getCommitSha1 = { -> def stdout = new ByteArrayOutputStream() @@ -74,6 +72,7 @@ android { buildConfigField "String", "EMULATOR_HOST", "\"10.0.2.2\"" buildConfigField "int", "FIRESTORE_EMULATOR_PORT", "8080" buildConfigField "int", "AUTH_EMULATOR_PORT", "9099" + manifestPlaceholders.usesCleartextTraffic = true } // Use flag -PtestBuildType with desired variant to change default behavior. @@ -127,7 +126,16 @@ android { dimension "backend" versionNameSuffix "-dev" buildConfigField "boolean", "USE_EMULATORS", "false" - manifestPlaceholders.usesCleartextTraffic = false + } + sig { + dimension "backend" + versionNameSuffix "-sig" + buildConfigField "boolean", "USE_EMULATORS", "false" + } + ecam { + dimension "backend" + versionNameSuffix "-ecam" + buildConfigField "boolean", "USE_EMULATORS", "false" } } diff --git a/ground/google-services.json b/ground/google-services.json deleted file mode 100644 index cc726f8b81..0000000000 --- a/ground/google-services.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "project_info": { - "project_number": "", - "project_id": "" - }, - "client": [ - { - "client_info": { - "mobilesdk_app_id": "1:692826002572:android:73e4ce15d6fedb129817a9", - "android_client_info": { - "package_name": "com.google.android.ground" - } - }, - "oauth_client": [ - { - "client_id": "", - "client_type": 3 - }, - { - "client_id": "", - "client_type": 1, - "android_info": { - "package_name": "com.google.android.ground", - "certificate_hash": "" - } - } - ], - "api_key": [ - { - "current_key": "" - } - ], - "services": { - "analytics_service": { - "status": 2, - "analytics_property": { - "tracking_id": "" - } - }, - "appinvite_service": { - "status": 1, - "other_platform_oauth_client": [] - }, - "ads_service": { - "status": 1 - } - } - } - ], - "configuration_version": "1" -} \ No newline at end of file diff --git a/sharedTest/build.gradle b/sharedTest/build.gradle index 4d8cfddcc1..61158daeb1 100644 --- a/sharedTest/build.gradle +++ b/sharedTest/build.gradle @@ -42,6 +42,12 @@ android { dev { dimension "backend" } + sig { + dimension "backend" + } + ecam { + dimension "backend" + } } }