Skip to content

Commit

Permalink
Migrate to Firebase Crashlytics
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirWrites committed May 18, 2020
1 parent be27271 commit e51e104
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package com.vlad1m1r.bltaxi.analytics

import android.content.Context
import android.content.SharedPreferences
import com.crashlytics.android.Crashlytics
import com.crashlytics.android.core.CrashlyticsCore
import io.fabric.sdk.android.Fabric
import com.google.firebase.crashlytics.FirebaseCrashlytics

internal class CrashReportImpl(
private val context: Context,
private val firebaseCrashlytics: FirebaseCrashlytics,
private val sharedPreferences: SharedPreferences
): CrashReport {
override fun initialize() {
Expand All @@ -21,13 +20,6 @@ internal class CrashReportImpl(
}

override fun enableCrashReporting(enabled: Boolean) {
val crashlytics = Crashlytics.Builder()
.core(
CrashlyticsCore.Builder()
.disabled(!enabled)
.build()
)
.build()
Fabric.with(context, crashlytics)
firebaseCrashlytics.setCrashlyticsCollectionEnabled(enabled)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vlad1m1r.bltaxi.analytics.di

import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.vlad1m1r.bltaxi.analytics.CrashReport
import com.vlad1m1r.bltaxi.analytics.CrashReportImpl
import com.vlad1m1r.bltaxi.analytics.Tracker
Expand All @@ -10,6 +11,7 @@ import org.koin.dsl.module

val analyticsModule = module {
single { FirebaseAnalytics.getInstance(androidContext()) }
single { FirebaseCrashlytics.getInstance() }
single<Tracker> { TrackerImpl(get(), androidContext(), get()) }
single<CrashReport> { CrashReportImpl(androidContext(), get()) }
single<CrashReport> { CrashReportImpl(androidContext(), get(), get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.app.Activity
import android.os.Build
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.truth.Truth.assertThat
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.nhaarman.mockitokotlin2.mock
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
Expand All @@ -14,9 +16,9 @@ import org.robolectric.annotation.Config
class CrashReportShould {

val context = InstrumentationRegistry.getInstrumentation().targetContext

val firebaseCrashlytics = mock<FirebaseCrashlytics>()
val sharedPreferences = context.getSharedPreferences(context.packageName, Activity.MODE_PRIVATE);
val crashReport: CrashReport = CrashReportImpl(context, sharedPreferences)
val crashReport: CrashReport = CrashReportImpl(context, firebaseCrashlytics, sharedPreferences)

@Test
fun initialize_whenNotInitialized() {
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: 'jacoco'
apply plugin: 'com.google.firebase.crashlytics'

jacoco {
toolVersion = Versions.jacoco
Expand Down
6 changes: 1 addition & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
name 'Fabric'
}
}
dependencies {
classpath Deps.android_gradle_plugin
classpath Deps.kotlin_gradle_plugin
classpath Deps.google_services_plugin
classpath Deps.fabric_plugin
classpath Deps.crashlytics_gradle_plugin
classpath Deps.jacoco_plugin
}
}
Expand Down
10 changes: 5 additions & 5 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Versions {

const val firebase_core = "17.4.1"
const val firebase_analytics = "17.4.1"
const val firebase_crashlytics = "2.10.1"
const val firebase_crashlytics = "17.0.0"

const val koin = "2.1.5"

Expand All @@ -39,7 +39,7 @@ object Versions {

const val gradle_android = "3.6.2"
const val google_services = "4.3.3"
const val fabric_plugin = "1.31.2"
const val crashlytics_gradle_plugin = "2.1.0"
const val jacoco = "0.8.5"

const val min_sdk = 21
Expand Down Expand Up @@ -67,14 +67,14 @@ object Deps {
const val work_manager = "androidx.work:work-runtime-ktx:${Versions.android_x_work_manager}"
const val databinding_compiler = "androidx.databinding:databinding-compiler:${Versions.android_x_databinding_compiler}"

const val lifecycle = "androidx.lifecycle:lifecycle-viewmodel:${Versions.android_x_lifecycle}"
const val lifecycle = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.android_x_lifecycle}"

const val navigation_fragment = "androidx.navigation:navigation-fragment-ktx:${Versions.android_x_navigation}"
const val navigation_ui = "androidx.navigation:navigation-ui-ktx:${Versions.android_x_navigation}"

const val firebase_core = "com.google.firebase:firebase-core:${Versions.firebase_core}"
const val firebase_analytics = "com.google.firebase:firebase-analytics:${Versions.firebase_analytics}"
const val firebase_crashlytics = "com.crashlytics.sdk.android:crashlytics:${Versions.firebase_crashlytics}"
const val firebase_crashlytics = "com.google.firebase:firebase-crashlytics:${Versions.firebase_crashlytics}"

const val koin = "org.koin:koin-android:${Versions.koin}"
const val koin_viewmodel = "org.koin:koin-androidx-viewmodel:${Versions.koin}"
Expand Down Expand Up @@ -106,7 +106,7 @@ object Deps {
const val android_gradle_plugin = "com.android.tools.build:gradle:${Versions.gradle_android}"
const val kotlin_gradle_plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
const val google_services_plugin = "com.google.gms:google-services:${Versions.google_services}"
const val fabric_plugin = "io.fabric.tools:gradle:${Versions.fabric_plugin}"
const val crashlytics_gradle_plugin = "com.google.firebase:firebase-crashlytics-gradle:${Versions.crashlytics_gradle_plugin}"
const val jacoco_plugin = "org.jacoco:org.jacoco.core:${Versions.jacoco}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.vlad1m1r.basedata.exhaustive
import com.vlad1m1r.baseui.CoroutineDispatcherProvider
import com.vlad1m1r.bltaxi.analytics.Tracker
import com.vlad1m1r.bltaxi.analytics.events.CallEvent
Expand Down

0 comments on commit e51e104

Please sign in to comment.