Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per-deployment flavors to ensure correct backend is used #2036

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
34 changes: 8 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
24 changes: 16 additions & 8 deletions ground/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
}
}

Expand Down
51 changes: 0 additions & 51 deletions ground/google-services.json

This file was deleted.

6 changes: 6 additions & 0 deletions sharedTest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ android {
dev {
dimension "backend"
}
sig {
dimension "backend"
}
ecam {
dimension "backend"
}
}
}

Expand Down