Skip to content

Commit

Permalink
chore: Updated Firebase dependencies and moved initialization
Browse files Browse the repository at this point in the history
Updated Firebase BOM and Crashlytics Gradle plugin to the latest versions.
Moved Firebase initialization to the Application
 class for better app lifecycle management.
Removed redundant plugin application from the `playstore` product flavor.

Anyways, Firebase still doesn't work at release build

Signed-off-by: Gabriel Fontán <[email protected]>
  • Loading branch information
BobbyESP committed Aug 1, 2024
1 parent 76909ff commit ae8b9cd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
9 changes: 6 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
import java.util.Properties

val isFullBuild: Boolean by rootProject.extra
val isGoogleMobileServicesBuild: Boolean by rootProject.extra

plugins {
alias(libs.plugins.android.application)
Expand All @@ -13,6 +13,11 @@ plugins {
alias(libs.plugins.compose.compiler)
}

if (isGoogleMobileServicesBuild) {
apply(plugin = libs.plugins.google.gms.get().pluginId)
apply(plugin = libs.plugins.firebase.crashlytics.get().pluginId)
}

val commitSignature = providers.exec {
commandLine("git", "rev-parse", "--short", "HEAD")
}.standardOutput.asText.get().substringBefore("\n")
Expand Down Expand Up @@ -80,8 +85,6 @@ android {
productFlavors {
create("playstore") {
dimension = "version"
apply(plugin = libs.plugins.google.gms.get().pluginId)
apply(plugin = libs.plugins.firebase.crashlytics.get().pluginId)
configure<CrashlyticsExtension> {
mappingFileUploadEnabled = false //Todo: SET TO TRUE WHEN FIXED
nativeSymbolUploadEnabled = false
Expand Down
11 changes: 9 additions & 2 deletions app/src/foss/kotlin/FirebaseSetup.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import com.bobbyesp.metadator.App
import com.bobbyesp.metadator.MainActivity

/**
* Setup Firebase for the app.
* Initialize Firebase services.
* EMPTY Because this is part of the FOSS flavour of the app.
*/
fun MainActivity.setupFirebase() {}
fun App.initializeFirebase() {}

/**
* Setup Crashlytics collection to the app.
* EMPTY Because this is part of the FOSS flavour of the app.
*/
fun MainActivity.setCrashlyticsCollection() {}
2 changes: 2 additions & 0 deletions app/src/main/java/com/bobbyesp/metadator/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.bobbyesp.crashhandler.CrashHandler.setupCrashHandler
import com.bobbyesp.crashhandler.ReportInfo
import com.tencent.mmkv.MMKV
import dagger.hilt.android.HiltAndroidApp
import initializeFirebase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlin.properties.Delegates
Expand All @@ -19,6 +20,7 @@ import kotlin.properties.Delegates
class App : Application() {
override fun onCreate() {
MMKV.initialize(this)
initializeFirebase()
packageInfo = packageManager.run {
if (Build.VERSION.SDK_INT >= 33) getPackageInfo(
packageName, PackageManager.PackageInfoFlags.of(0)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/bobbyesp/metadator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.bobbyesp.metadator.presentation.Navigator
import com.bobbyesp.metadator.presentation.common.AppLocalSettingsProvider
import com.bobbyesp.metadator.presentation.theme.MetadatorTheme
import dagger.hilt.android.AndroidEntryPoint
import setupFirebase
import setCrashlyticsCollection
import javax.inject.Inject

@androidx.annotation.OptIn(UnstableApi::class)
Expand All @@ -43,7 +43,7 @@ class MainActivity : ComponentActivity() {
insets
}
activity = this
setupFirebase()
setCrashlyticsCollection()
setContent {
val windowSizeClass = calculateWindowSizeClass(this)
AppLocalSettingsProvider(windowSizeClass.widthSizeClass, connectionHandler) {
Expand Down
14 changes: 13 additions & 1 deletion app/src/playstore/kotlin/FirebaseSetup.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import com.bobbyesp.metadator.App
import com.bobbyesp.metadator.MainActivity
import com.google.firebase.Firebase
import com.google.firebase.crashlytics.crashlytics
import com.google.firebase.initialize

fun MainActivity.setupFirebase() {
fun App.initializeFirebase() {
Firebase.initialize(this)
}

/**
* Extension function for MainActivity to enable Crashlytics collection.
*
* This function sets the Crashlytics collection to be enabled, allowing Firebase Crashlytics
* to collect crash reports for the application.
*/
fun MainActivity.setCrashlyticsCollection() {
Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
#General, lifecycle and core
agp = "8.7.0-alpha02"
firebaseCrashlyticsGradle = "2.9.0"
firebaseCrashlyticsGradle = "3.0.2"
kotlin = "2.0.0"
appcompat = "1.7.0"
core-ktx = "1.13.1"
Expand Down Expand Up @@ -59,7 +59,7 @@ mmkv = "1.3.9"
#Firebase, GMS...
gmsPlayServicesAuth = "21.2.0"
googleServices = "4.4.2"
firebaseBom = "33.1.2"
firebaseBom = "33.1.1"

#Spotify API
spotify-apiHandler = "4.1.3"
Expand Down

0 comments on commit ae8b9cd

Please sign in to comment.