From 1225fcf1a65884aeade76a9706d939c2dfc11689 Mon Sep 17 00:00:00 2001 From: Gino Miceli Date: Thu, 2 Nov 2023 11:54:40 -0400 Subject: [PATCH 1/3] Clean up config, add flavors --- CONTRIBUTING.md | 34 ++++++------------------- ground/build.gradle | 24 +++++++++++------ ground/google-services.json | 51 ------------------------------------- sharedTest/build.gradle | 6 +++++ 4 files changed, 30 insertions(+), 85 deletions(-) delete mode 100644 ground/google-services.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b57312f688..d3f95d7659 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/dev/google-services.json` ### Set up Google Cloud Build (optional) @@ -211,7 +193,7 @@ $ gcloud builds submit --config=cloudbuild.yaml --substitutions=_ANDROID_VERSION java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.IllegalArgumentException: Given String is empty or null ``` - Solution: Ensure `ground/src/debug/google-services.json` exists and is valid, as per instructions in [Set up Firebase](#set-up-firebase). You may need to perform a clean build in Android Studio by going to Build -> Clean Project. + Solution: Ensure `ground/src/debug/dev/google-services.json` exists and is valid, as per instructions in [Set up Firebase](#set-up-firebase). You may need to perform a clean build in Android Studio by going to Build -> Clean Project. * Gradle Build fails with "License for package Android SDK Platform ... not accepted": diff --git a/ground/build.gradle b/ground/build.gradle index d4e14fced2..9b01fa11b0 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/dev/google-services.json") +def json = new JsonSlurper().parseText(inputFile.text) +def googleMapsApiKey = 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" + } } } From 6446c1b95f2e757d56b3d61a62c580cacdbee179 Mon Sep 17 00:00:00 2001 From: Gino Miceli Date: Thu, 2 Nov 2023 12:11:21 -0400 Subject: [PATCH 2/3] Fix for local emu --- .gitignore | 5 ----- CONTRIBUTING.md | 6 +++--- ground/build.gradle | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) 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 d3f95d7659..ce89b849b9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -154,7 +154,7 @@ either the commit message for your changes or in your pull request. $ 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/dev/google-services.json` +4. Download the config file for the Android app to `ground/src/debug/google-services.json` ### Set up Google Cloud Build (optional) @@ -183,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 @@ -193,7 +193,7 @@ $ gcloud builds submit --config=cloudbuild.yaml --substitutions=_ANDROID_VERSION java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.IllegalArgumentException: Given String is empty or null ``` - Solution: Ensure `ground/src/debug/dev/google-services.json` exists and is valid, as per instructions in [Set up Firebase](#set-up-firebase). You may need to perform a clean build in Android Studio by going to Build -> Clean Project. + Solution: Ensure `ground/src/debug/google-services.json` exists and is valid, as per instructions in [Set up Firebase](#set-up-firebase). You may need to perform a clean build in Android Studio by going to Build -> Clean Project. * Gradle Build fails with "License for package Android SDK Platform ... not accepted": diff --git a/ground/build.gradle b/ground/build.gradle index 9b01fa11b0..38dd1e8bfa 100644 --- a/ground/build.gradle +++ b/ground/build.gradle @@ -42,7 +42,7 @@ project.ext { // Extract API key from google-services.json for use with Google Maps SDK. import groovy.json.JsonSlurper -def inputFile = new File("ground/src/debug/dev/google-services.json") +def inputFile = new File("ground/src/debug/google-services.json") def json = new JsonSlurper().parseText(inputFile.text) def googleMapsApiKey = json.client[0].api_key[0].current_key From 67585a14bf5bbc78b288412e6abe8221cc4a4b69 Mon Sep 17 00:00:00 2001 From: Gino Miceli Date: Thu, 2 Nov 2023 13:37:45 -0400 Subject: [PATCH 3/3] Fix CI build --- ground/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ground/build.gradle b/ground/build.gradle index 38dd1e8bfa..dd7eb793da 100644 --- a/ground/build.gradle +++ b/ground/build.gradle @@ -43,8 +43,8 @@ project.ext { // 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 = new JsonSlurper().parseText(inputFile.text) -def googleMapsApiKey = json.client[0].api_key[0].current_key +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()