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

feat: Firebase config #233

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 21 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'com.google.firebase.crashlytics'
}

def config = configHelper.fetchConfig()
def appId = config.getOrDefault("APPLICATION_ID", "org.openedx.app")
def platformName = config.getOrDefault("PLATFORM_NAME", "OpenEdx").toLowerCase()
def firebaseConfig = config.get('FIREBASE')
def firebaseEnabled = firebaseConfig?.getOrDefault('ENABLED', false)

apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
if (firebaseEnabled) {
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

tasks.register('generateGoogleServicesJson') {
configHelper.generateGoogleServicesJson(appId)
}

preBuild.dependsOn(generateGoogleServicesJson)
}

android {
compileSdk 34
Expand Down Expand Up @@ -57,8 +66,10 @@ android {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

firebaseCrashlytics {
mappingFileUploadEnabled false
if (firebaseEnabled) {
firebaseCrashlytics {
mappingFileUploadEnabled false
}
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions app/src/main/java/org/openedx/app/OpenEdXApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ class OpenEdXApp : Application() {
screenModule
)
}
val firebaseConfig = config.getFirebaseConfig()
if (firebaseConfig.enabled) {
val options = FirebaseOptions.Builder()
.setProjectId(firebaseConfig.projectId)
.setApplicationId(firebaseConfig.applicationId)
.setApiKey(firebaseConfig.apiKey)
.setGcmSenderId(firebaseConfig.gcmSenderId)
.build()
Firebase.initialize(this, options)
if (config.getFirebaseConfig().enabled) {
Firebase.initialize(this)
}
}

Expand Down
45 changes: 45 additions & 0 deletions buildSrc/src/main/groovy/org/edx/builder/ConfigHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,49 @@ class ConfigHelper {
it.write(new JsonBuilder(configJson).toPrettyString())
}
}

def generateGoogleServicesJson(applicationId) {
def config = fetchConfig()
def firebase = config.get("FIREBASE")
if (!firebase) {
return
}
if (!firebase.getOrDefault("ENABLED", false)) {
return
}

def googleServicesJsonPath = projectDir.path + "/app/"
new File(googleServicesJsonPath).mkdirs()

def projectInfo = [
project_number: firebase.getOrDefault("PROJECT_NUMBER", ""),
project_id : firebase.getOrDefault("PROJECT_ID", ""),
storage_bucket: "${firebase.getOrDefault("PROJECT_ID", "")}.appspot.com"
]
def clientInfo = [
mobilesdk_app_id : firebase.getOrDefault("APPLICATION_ID", ""),
android_client_info: [
package_name: applicationId
]
]
def client = [
client_info : clientInfo,
oauth_client: [],
api_key : [[current_key: firebase.getOrDefault("API_KEY", "")]],
services : [
appinvite_service: [
other_platform_oauth_client: []
]
]
]
def configJson = [
project_info : projectInfo,
client : [client],
configuration_version: "1"
]

new FileWriter(googleServicesJsonPath + "/google-services.json").withWriter {
it.write(new JsonBuilder(configJson).toPrettyString())
}
}
}
6 changes: 3 additions & 3 deletions core/src/main/java/org/openedx/core/config/FirebaseConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ data class FirebaseConfig(
@SerializedName("ENABLED")
val enabled: Boolean = false,

@SerializedName("PROJECT_NUMBER")
val gcmSenderId: String = "",

@SerializedName("PROJECT_ID")
val projectId: String = "",

Expand All @@ -14,7 +17,4 @@ data class FirebaseConfig(

@SerializedName("API_KEY")
val apiKey: String = "",

@SerializedName("GCM_SENDER_ID")
val gcmSenderId: String = "",
)
7 changes: 7 additions & 0 deletions default_config/dev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ PROGRAM:
PROGRAM_URL: ''
PROGRAM_DETAIL_URL_TEMPLATE: ''

FIREBASE:
ENABLED: false
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''

GOOGLE:
ENABLED: false
CLIENT_ID: ''
Expand Down
7 changes: 7 additions & 0 deletions default_config/prod/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ PROGRAM:
PROGRAM_URL: ''
PROGRAM_DETAIL_URL_TEMPLATE: ''

FIREBASE:
ENABLED: false
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''

GOOGLE:
ENABLED: false
CLIENT_ID: ''
Expand Down
7 changes: 7 additions & 0 deletions default_config/stage/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ PROGRAM:
PROGRAM_URL: ''
PROGRAM_DETAIL_URL_TEMPLATE: ''

FIREBASE:
ENABLED: false
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''

GOOGLE:
ENABLED: false
CLIENT_ID: ''
Expand Down
Loading