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 3 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)

farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
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
}
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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) {
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
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", ""),
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
android_client_info: [
package_name: applicationId
]
]
def client = [
client_info : clientInfo,
oauth_client: [],
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
api_key : [[current_key: firebase.getOrDefault("API_KEY", "")]],
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
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())
}
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
}
}
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 @@ -9,6 +9,9 @@ data class FirebaseConfig(
@SerializedName("ANALYTICS_SOURCE")
val analyticsSource: AnalyticsSource = AnalyticsSource.NONE,

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

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

Expand All @@ -17,9 +20,6 @@ data class FirebaseConfig(

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

@SerializedName("GCM_SENDER_ID")
val gcmSenderId: String = "",
) {
fun isSegmentAnalyticsSource(): Boolean {
return enabled && analyticsSource == AnalyticsSource.SEGMENT
Expand Down
9 changes: 5 additions & 4 deletions default_config/dev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ FIREBASE:
ENABLED: false
ANALYTICS_SOURCE: '' # segment | none
CLOUD_MESSAGING_ENABLED: false
PROJECT_ID: ""
APPLICATION_ID: ""
API_KEY: ""
GCM_SENDER_ID: ""
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''
GCM_SENDER_ID: ''
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved

SEGMENT_IO:
ENABLED: false
Expand Down
9 changes: 5 additions & 4 deletions default_config/prod/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ FIREBASE:
ENABLED: false
ANALYTICS_SOURCE: '' # segment | none
CLOUD_MESSAGING_ENABLED: false
PROJECT_ID: ""
APPLICATION_ID: ""
API_KEY: ""
GCM_SENDER_ID: ""
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''
GCM_SENDER_ID: ''

SEGMENT_IO:
ENABLED: false
Expand Down
9 changes: 5 additions & 4 deletions default_config/stage/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ FIREBASE:
ENABLED: false
ANALYTICS_SOURCE: '' # segment | none
CLOUD_MESSAGING_ENABLED: false
PROJECT_ID: ""
APPLICATION_ID: ""
API_KEY: ""
GCM_SENDER_ID: ""
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''
GCM_SENDER_ID: ''

SEGMENT_IO:
ENABLED: false
Expand Down
Loading