Skip to content

Commit

Permalink
Merge pull request #140 from AoEiuV020/p1
Browse files Browse the repository at this point in the history
修复没有谷歌配置文件无法运行的问题
  • Loading branch information
aaa1115910 authored Jun 16, 2024
2 parents 4f81589 + f2edc2d commit c328eac
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
8 changes: 7 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ plugins {
alias(gradleLibs.plugins.compose.compiler)
alias(gradleLibs.plugins.firebase.crashlytics)
alias(gradleLibs.plugins.google.ksp)
alias(gradleLibs.plugins.google.services)
alias(gradleLibs.plugins.google.services) apply false
alias(gradleLibs.plugins.kotlin.android)
alias(gradleLibs.plugins.kotlin.serialization)
}
if (file("google-services.json").let {
it.exists() && it.readText().contains(AppConfiguration.appId)
}) {
apply(plugin = gradleLibs.plugins.google.services.get().pluginId)
}


val signingProp = file(project.rootProject.file("signing.properties"))

Expand Down
7 changes: 2 additions & 5 deletions app/src/main/kotlin/dev/aaa1115910/bv/BVApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import android.util.Log
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
import de.schnettler.datastore.manager.DataStoreManager
import dev.aaa1115910.biliapi.http.BiliHttpProxyApi
import dev.aaa1115910.biliapi.repositories.AuthRepository
Expand All @@ -30,6 +27,7 @@ import dev.aaa1115910.bv.network.HttpServer
import dev.aaa1115910.bv.repository.UserRepository
import dev.aaa1115910.bv.repository.VideoInfoRepository
import dev.aaa1115910.bv.screen.user.UserSwitchViewModel
import dev.aaa1115910.bv.util.FirebaseUtil
import dev.aaa1115910.bv.util.LogCatcherUtil
import dev.aaa1115910.bv.util.Prefs
import dev.aaa1115910.bv.viewmodel.PlayerViewModel
Expand Down Expand Up @@ -67,7 +65,6 @@ class BVApp : Application() {
lateinit var context: Context
lateinit var dataStoreManager: DataStoreManager
lateinit var koinApplication: KoinApplication
lateinit var firebaseAnalytics: FirebaseAnalytics
var instance: BVApp? = null

fun getAppDatabase(context: Context = this.context) = AppDatabase.getDatabase(context)
Expand All @@ -83,7 +80,7 @@ class BVApp : Application() {
androidContext(this@BVApp)
modules(appModule)
}
firebaseAnalytics = Firebase.analytics
FirebaseUtil.init(applicationContext)
LogCatcherUtil.installLogCatcher()
initRepository()
initProxy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ import androidx.compose.ui.unit.dp
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import dev.aaa1115910.bv.BuildConfig
import dev.aaa1115910.bv.R
import dev.aaa1115910.bv.activities.settings.LogsActivity
import dev.aaa1115910.bv.component.settings.CookiesDialog
import dev.aaa1115910.bv.component.settings.SettingListItem
import dev.aaa1115910.bv.component.settings.SettingSwitchListItem
import dev.aaa1115910.bv.screen.settings.SettingsMenuNavItem
import dev.aaa1115910.bv.util.FirebaseUtil
import dev.aaa1115910.bv.util.Prefs

@Composable
Expand Down Expand Up @@ -67,9 +65,7 @@ fun OtherSetting(
checked = Prefs.enableFirebaseCollection,
onCheckedChange = {
Prefs.enableFirebaseCollection = it
Firebase.crashlytics.setCrashlyticsCollectionEnabled(it)
FirebaseAnalytics.getInstance(context)
.setAnalyticsCollectionEnabled(it)
FirebaseUtil.setCrashlyticsCollectionEnabled(it)
}
)
}
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/kotlin/dev/aaa1115910/bv/util/FirebaseUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.aaa1115910.bv.util

import android.content.Context
import com.google.firebase.FirebaseApp
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase

object FirebaseUtil {
private var initialized = false

fun init(context: Context) {
initialized = FirebaseApp.initializeApp(context) != null
}

fun log(msg: String) {
if (!initialized) return
Firebase.crashlytics.log(msg)
}

fun recordException(throwable: Throwable) {
if (!initialized) return
Firebase.crashlytics.recordException(throwable)
}

fun setCrashlyticsCollectionEnabled(enable: Boolean) {
if (!initialized) return
Firebase.crashlytics.setCrashlyticsCollectionEnabled(enable)
Firebase.analytics.setAnalyticsCollectionEnabled(enable)
}

}
18 changes: 10 additions & 8 deletions app/src/main/kotlin/dev/aaa1115910/bv/util/KLoggerExtends.kt
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
package dev.aaa1115910.bv.util

import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import dev.aaa1115910.bv.BuildConfig
import io.github.oshai.kotlinlogging.KLogger

fun KLogger.fInfo(msg: () -> Any?) {
info(msg)
Firebase.crashlytics.log("[Info] ${msg.toStringSafe()}")
firebaseLog("[Info] ${msg.toStringSafe()}")
}

fun KLogger.fWarn(msg: () -> Any?) {
warn(msg)
Firebase.crashlytics.log("[Warn] ${msg.toStringSafe()}")
firebaseLog("[Warn] ${msg.toStringSafe()}")
}

fun KLogger.fDebug(msg: () -> Any?) {
if (BuildConfig.DEBUG) {
info(msg)
Firebase.crashlytics.log("[Debug] ${msg.toStringSafe()}")
firebaseLog("[Debug] ${msg.toStringSafe()}")
}
}

fun KLogger.fError(msg: () -> Any?) {
error(msg)
Firebase.crashlytics.log("[Error] ${msg.toStringSafe()}")
firebaseLog("[Error] ${msg.toStringSafe()}")
}

fun KLogger.fException(throwable: Throwable, msg: () -> Any?) {
warn { "$msg: ${throwable.stackTraceToString()}" }
Firebase.crashlytics.log("[Exception] ${msg.toStringSafe()}: ${throwable.localizedMessage}")
Firebase.crashlytics.recordException(throwable)
firebaseLog("[Exception] ${msg.toStringSafe()}: ${throwable.localizedMessage}")
FirebaseUtil.recordException(throwable)
}

private fun firebaseLog(msg: String) {
FirebaseUtil.log(msg)
}

@Suppress("NOTHING_TO_INLINE")
Expand Down

0 comments on commit c328eac

Please sign in to comment.