Skip to content

Commit

Permalink
Merge pull request #2717 from dimagi/move_firebase_url_to_android_sec…
Browse files Browse the repository at this point in the history
…rets

Move Firebase Database URL to Android secrets
  • Loading branch information
avazirna authored Oct 11, 2023
2 parents 8407441 + f3039d0 commit 1776bb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,31 @@ ext {
HQ_API_USERNAME = project.properties['HQ_API_USERNAME'] ?: ""
HQ_API_PASSWORD = project.properties['HQ_API_PASSWORD'] ?: ""
TEST_BUILD_TYPE = project.properties['TEST_BUILD_TYPE'] ?: "debug"
FIREBASE_DATABASE_URL = project.properties['FIREBASE_DATABASE_URL'] ?: ""
}

afterEvaluate {
// Hack to get assets to show up in robolectric tests; try to eventually remove this
preCommcareDebugUnitTestBuild.dependsOn mergeCommcareDebugAssets
processStandaloneDebugGoogleServices.dependsOn injectGoogleServicesAPIKey
processStandaloneReleaseGoogleServices.dependsOn injectGoogleServicesAPIKey
processLtsDebugGoogleServices.dependsOn injectGoogleServicesAPIKey
processLtsReleaseGoogleServices.dependsOn injectGoogleServicesAPIKey
processCommcareDebugGoogleServices.dependsOn injectGoogleServicesAPIKey
processCommcareReleaseGoogleServices.dependsOn injectGoogleServicesAPIKey
processStandaloneDebugGoogleServices.dependsOn injectPropertiesIntoFirebaseConfigFile
processStandaloneReleaseGoogleServices.dependsOn injectPropertiesIntoFirebaseConfigFile
processLtsDebugGoogleServices.dependsOn injectPropertiesIntoFirebaseConfigFile
processLtsReleaseGoogleServices.dependsOn injectPropertiesIntoFirebaseConfigFile
processCommcareDebugGoogleServices.dependsOn injectPropertiesIntoFirebaseConfigFile
processCommcareReleaseGoogleServices.dependsOn injectPropertiesIntoFirebaseConfigFile
}

/**
* https://discuss.gradle.org/t/gradle-7-0-seems-to-take-an-overzealous-approach-to-inter-task-dependencies/39656/2
* Gradle 7.0 treats any copy tasks as having an implicit dependencies with each other.
*/
task injectGoogleServicesAPIKey {
description = 'Injects the Google Services API key into the google-services.json file at runtime'
task injectPropertiesIntoFirebaseConfigFile {
description = 'Injects properties into the google-services.json file at runtime'

copy {
from 'templates/google-services.json'
filter(ReplaceTokens, tokens: [apiKey: project.ext.GOOGLE_SERVICES_API_KEY])
filter(ReplaceTokens, tokens: [apiKey: project.ext.GOOGLE_SERVICES_API_KEY,
firebaseDatabaseUrl: project.ext.FIREBASE_DATABASE_URL])
into projectDir
}
}
Expand Down Expand Up @@ -272,7 +274,7 @@ android {

buildConfigField "String", "HQ_API_USERNAME", "\"${project.ext.HQ_API_USERNAME}\""
buildConfigField "String", "HQ_API_PASSWORD", "\"${project.ext.HQ_API_PASSWORD}\""

buildConfigField "String", "FIREBASE_DATABASE_URL", "\"${project.ext.FIREBASE_DATABASE_URL}\""
testInstrumentationRunner "org.commcare.CommCareJUnitRunner"
}

Expand Down
2 changes: 1 addition & 1 deletion app/templates/google-services.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"project_info": {
"project_number": "768065119425",
"firebase_url": "https://commcare-a57e4.firebaseio.com",
"firebase_url": "@firebaseDatabaseUrl@",
"project_id": "commcare-a57e4",
"storage_bucket": "commcare-a57e4.appspot.com"
},
Expand Down

0 comments on commit 1776bb8

Please sign in to comment.