Skip to content

Commit

Permalink
refactor: build config fields
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill committed Nov 7, 2023
1 parent 2e7ead1 commit 285a6af
Showing 1 changed file with 23 additions and 54 deletions.
77 changes: 23 additions & 54 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,66 +40,15 @@ android {
productFlavors {
prod {
dimension 'env'

def envMap = config.environments.find { it.key == "PROD" }
def clientId = envMap.value.OAUTH_CLIENT_ID
def envUrls = envMap.value.URLS
def firebase = getFirebaseConfig(envMap)

buildConfigField "String", "BASE_URL", "\"${envUrls.API_HOST_URL}\""
buildConfigField "String", "CLIENT_ID", "\"${clientId}\""
buildConfigField "String", "FIREBASE_PROJECT_ID", "\"${firebase.projectId}\""
buildConfigField "String", "FIREBASE_API_KEY", "\"${firebase.apiKey}\""
buildConfigField "String", "FIREBASE_GCM_SENDER_ID", "\"${firebase.gcmSenderId}\""
resValue "string", "google_app_id", firebase.appId
resValue "string", "platform_name", config.platformName
resValue "string", "platform_full_name", config.platformFullName
resValue "string", "privacy_policy_link", envUrls.privacyPolicy
resValue "string", "terms_of_service_link", envUrls.termsOfService
resValue "string", "contact_us_link", envUrls.contactUs
resValue "string", "feedback_email_address", envUrls.FEEDBACK_EMAIL_ADDRESS
insertBuildConfigFields(config, it, "PROD")
}
develop {
dimension 'env'

def envMap = config.environments.find { it.key == "DEV" }
def clientId = envMap.value.OAUTH_CLIENT_ID
def envUrls = envMap.value.URLS
def firebase = getFirebaseConfig(envMap)

buildConfigField "String", "BASE_URL", "\"${envUrls.API_HOST_URL}\""
buildConfigField "String", "CLIENT_ID", "\"${clientId}\""
buildConfigField "String", "FIREBASE_PROJECT_ID", "\"${firebase.projectId}\""
buildConfigField "String", "FIREBASE_API_KEY", "\"${firebase.apiKey}\""
buildConfigField "String", "FIREBASE_GCM_SENDER_ID", "\"${firebase.gcmSenderId}\""
resValue "string", "google_app_id", firebase.appId
resValue "string", "platform_name", config.platformName
resValue "string", "platform_full_name", config.platformFullName
resValue "string", "privacy_policy_link", envUrls.privacyPolicy
resValue "string", "terms_of_service_link", envUrls.termsOfService
resValue "string", "contact_us_link", envUrls.contactUs
resValue "string", "feedback_email_address", envUrls.FEEDBACK_EMAIL_ADDRESS
insertBuildConfigFields(config, it, "DEV")
}
stage {
dimension 'env'

def envMap = config.environments.find { it.key == "STAGE" }
def clientId = envMap.value.OAUTH_CLIENT_ID
def envUrls = envMap.value.URLS
def firebase = getFirebaseConfig(envMap)

buildConfigField "String", "BASE_URL", "\"${envUrls.API_HOST_URL}\""
buildConfigField "String", "CLIENT_ID", "\"${clientId}\""
buildConfigField "String", "FIREBASE_PROJECT_ID", "\"${firebase.projectId}\""
buildConfigField "String", "FIREBASE_API_KEY", "\"${firebase.apiKey}\""
buildConfigField "String", "FIREBASE_GCM_SENDER_ID", "\"${firebase.gcmSenderId}\""
resValue "string", "google_app_id", firebase.appId
resValue "string", "platform_name", config.platformName
resValue "string", "platform_full_name", config.platformFullName
resValue "string", "privacy_policy_link", envUrls.privacyPolicy
resValue "string", "terms_of_service_link", envUrls.termsOfService
resValue "string", "contact_us_link", envUrls.contactUs
resValue "string", "feedback_email_address", envUrls.FEEDBACK_EMAIL_ADDRESS
insertBuildConfigFields(config, it, "STAGE")
}
}

Expand Down Expand Up @@ -216,3 +165,23 @@ def setValue(value) {
}
return result
}

def insertBuildConfigFields(config, buildType, String keyName) {
def envMap = config.environments.find { it.key == keyName }
def clientId = envMap.value.OAUTH_CLIENT_ID
def envUrls = envMap.value.URLS
def firebase = getFirebaseConfig(envMap)

buildType.buildConfigField "String", "BASE_URL", "\"${envUrls.API_HOST_URL}\""
buildType.buildConfigField "String", "CLIENT_ID", "\"${clientId}\""
buildType.buildConfigField "String", "FIREBASE_PROJECT_ID", "\"${firebase.projectId}\""
buildType.buildConfigField "String", "FIREBASE_API_KEY", "\"${firebase.apiKey}\""
buildType.buildConfigField "String", "FIREBASE_GCM_SENDER_ID", "\"${firebase.gcmSenderId}\""
buildType.resValue "string", "google_app_id", firebase.appId
buildType.resValue "string", "platform_name", config.platformName
buildType.resValue "string", "platform_full_name", config.platformFullName
buildType.resValue "string", "privacy_policy_link", envUrls.privacyPolicy
buildType.resValue "string", "terms_of_service_link", envUrls.termsOfService
buildType.resValue "string", "contact_us_link", envUrls.contactUs
buildType.resValue "string", "feedback_email_address", envUrls.FEEDBACK_EMAIL_ADDRESS
}

0 comments on commit 285a6af

Please sign in to comment.