Migrate from fabric to firebase crashlytics (#789)
This commit is contained in:
@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'io.fabric'
|
||||
apply plugin: 'com.google.firebase.crashlytics'
|
||||
apply plugin: 'com.github.triplet.play'
|
||||
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
|
||||
apply from: 'jacoco.gradle'
|
||||
@ -24,8 +24,7 @@ android {
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
manifestPlaceholders = [
|
||||
fabric_api_key : System.getenv("FABRIC_API_KEY") ?: "null",
|
||||
crashlytics_enabled: project.hasProperty("enableCrashlytics")
|
||||
firebase_enabled: project.hasProperty("enableFirebase")
|
||||
]
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
@ -52,18 +51,16 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
buildConfigField "boolean", "CRASHLYTICS_ENABLED", "true"
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
debug {
|
||||
buildConfigField "boolean", "CRASHLYTICS_ENABLED", project.hasProperty("enableCrashlytics") ? "true" : "false"
|
||||
applicationIdSuffix ".dev"
|
||||
versionNameSuffix "-dev"
|
||||
testCoverageEnabled = project.hasProperty('coverage')
|
||||
ext.enableCrashlytics = project.hasProperty("enableCrashlytics")
|
||||
ext.enableCrashlytics = project.hasProperty("enableFirebase")
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +72,6 @@ android {
|
||||
}
|
||||
|
||||
fdroid {
|
||||
buildConfigField "boolean", "CRASHLYTICS_ENABLED", "false"
|
||||
dimension "platform"
|
||||
}
|
||||
}
|
||||
@ -190,8 +186,8 @@ dependencies {
|
||||
playImplementation 'com.google.firebase:firebase-analytics:17.4.0'
|
||||
playImplementation 'com.google.firebase:firebase-inappmessaging-display-ktx:19.0.6'
|
||||
playImplementation "com.google.firebase:firebase-inappmessaging-ktx:19.0.6"
|
||||
playImplementation "com.google.firebase:firebase-messaging:20.1.0"
|
||||
playImplementation "com.crashlytics.sdk.android:crashlytics:2.10.1"
|
||||
playImplementation 'com.google.firebase:firebase-messaging:20.1.6'
|
||||
playImplementation 'com.google.firebase:firebase-crashlytics:17.0.0'
|
||||
playImplementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
|
||||
|
||||
releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:$chucker"
|
||||
|
@ -107,12 +107,33 @@
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
|
||||
<!-- workaround for https://github.com/firebase/firebase-android-sdk/issues/473 enabled:false -->
|
||||
<!-- https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html -->
|
||||
<provider
|
||||
android:name="com.google.firebase.provider.FirebaseInitProvider"
|
||||
android:authorities="${applicationId}.firebaseinitprovider"
|
||||
android:enabled="${firebase_enabled}"
|
||||
android:exported="false" />
|
||||
|
||||
<meta-data
|
||||
android:name="io.fabric.ApiKey"
|
||||
android:value="${fabric_api_key}" />
|
||||
android:name="firebase_analytics_collection_enabled"
|
||||
android:value="${firebase_enabled}" />
|
||||
|
||||
<meta-data
|
||||
android:name="google_analytics_adid_collection_enabled"
|
||||
android:value="${firebase_enabled}" />
|
||||
|
||||
<meta-data
|
||||
android:name="firebase_crashlytics_collection_enabled"
|
||||
android:value="${crashlytics_enabled}" />
|
||||
android:value="${firebase_enabled}" />
|
||||
|
||||
<meta-data
|
||||
android:name="firebase_messaging_auto_init_enabled"
|
||||
android:value="${firebase_enabled}" />
|
||||
|
||||
<meta-data
|
||||
android:name="firebase_inapp_messaging_auto_data_collection_enabled"
|
||||
android:value="${firebase_enabled}" />
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.firebase.messaging.default_notification_icon"
|
||||
|
@ -19,7 +19,6 @@ import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.CrashlyticsExceptionTree
|
||||
import io.github.wulkanowy.utils.CrashlyticsTree
|
||||
import io.github.wulkanowy.utils.DebugLogTree
|
||||
import io.github.wulkanowy.utils.initCrashlytics
|
||||
import io.reactivex.exceptions.UndeliverableException
|
||||
import io.reactivex.plugins.RxJavaPlugins
|
||||
import timber.log.Timber
|
||||
@ -50,7 +49,6 @@ class WulkanowyApp : DaggerApplication(), Configuration.Provider {
|
||||
themeManager.applyDefaultTheme()
|
||||
|
||||
initLogging()
|
||||
initCrashlytics(this, appInfo)
|
||||
}
|
||||
|
||||
private fun initLogging() {
|
||||
|
@ -4,7 +4,6 @@ import android.content.res.Resources
|
||||
import android.os.Build.MANUFACTURER
|
||||
import android.os.Build.MODEL
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import io.github.wulkanowy.BuildConfig.CRASHLYTICS_ENABLED
|
||||
import io.github.wulkanowy.BuildConfig.DEBUG
|
||||
import io.github.wulkanowy.BuildConfig.VERSION_CODE
|
||||
import io.github.wulkanowy.BuildConfig.VERSION_NAME
|
||||
@ -13,8 +12,6 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
open class AppInfo {
|
||||
|
||||
open val isCrashlyticsEnabled get() = CRASHLYTICS_ENABLED
|
||||
|
||||
open val isDebug get() = DEBUG
|
||||
|
||||
open val versionCode get() = VERSION_CODE
|
||||
|
@ -1,36 +1,46 @@
|
||||
package io.github.wulkanowy.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import com.crashlytics.android.core.CrashlyticsCore
|
||||
import fr.bipi.tressence.crash.CrashlyticsLogExceptionTree
|
||||
import fr.bipi.tressence.crash.CrashlyticsLogTree
|
||||
import io.fabric.sdk.android.Fabric
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import fr.bipi.tressence.base.FormatterPriorityTree
|
||||
import fr.bipi.tressence.common.StackTraceRecorder
|
||||
import io.github.wulkanowy.sdk.exception.FeatureDisabledException
|
||||
import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
fun initCrashlytics(context: Context, appInfo: AppInfo) {
|
||||
Fabric.with(Fabric.Builder(context)
|
||||
.kits(
|
||||
Crashlytics.Builder()
|
||||
.core(CrashlyticsCore.Builder()
|
||||
.disabled(!appInfo.isCrashlyticsEnabled)
|
||||
.build())
|
||||
.build()
|
||||
)
|
||||
.debuggable(appInfo.isDebug)
|
||||
.build())
|
||||
}
|
||||
class CrashlyticsTree : FormatterPriorityTree(Log.VERBOSE) {
|
||||
|
||||
class CrashlyticsTree : CrashlyticsLogTree(Log.VERBOSE) {
|
||||
private val crashlytics by lazy { FirebaseCrashlytics.getInstance() }
|
||||
|
||||
override fun skipLog(priority: Int, tag: String?, message: String, t: Throwable?): Boolean {
|
||||
if (t is FeatureDisabledException || t is FeatureNotAvailableException || t is UnknownHostException) {
|
||||
return true
|
||||
}
|
||||
|
||||
return super.skipLog(priority, tag, message, t)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
if (t is FeatureDisabledException || t is FeatureNotAvailableException || t is UnknownHostException) return
|
||||
if (skipLog(priority, tag, message, t)) return
|
||||
|
||||
super.log(priority, tag, message, t)
|
||||
crashlytics.log(format(priority, tag, message))
|
||||
}
|
||||
}
|
||||
|
||||
class CrashlyticsExceptionTree : CrashlyticsLogExceptionTree()
|
||||
class CrashlyticsExceptionTree : FormatterPriorityTree(Log.ERROR) {
|
||||
|
||||
private val crashlytics by lazy { FirebaseCrashlytics.getInstance() }
|
||||
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
if (skipLog(priority, tag, message, t)) return
|
||||
|
||||
crashlytics.setCustomKey("priority", priority)
|
||||
crashlytics.setCustomKey("tag", tag.orEmpty())
|
||||
crashlytics.setCustomKey("message", message)
|
||||
if (t != null) {
|
||||
crashlytics.recordException(t)
|
||||
} else {
|
||||
crashlytics.recordException(StackTraceRecorder(format(priority, tag, message)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user