Skip to content

Commit

Permalink
Setup crash reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
msimonides committed Mar 16, 2024
1 parent 769ec53 commit 2682ab0
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 6 deletions.
19 changes: 18 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.ksp)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.aboutlibraries)
alias(libs.plugins.sentry)
}

def enableComposeMetrics = project.hasProperty("enableComposeMetrics") ? project["enableComposeMetrics"] : false
Expand Down Expand Up @@ -37,7 +38,7 @@ android {

buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand Down Expand Up @@ -67,6 +68,20 @@ android {
}
}

sentry {
tracingInstrumentation {
enabled = false
logcat {
enabled = false
}
}
autoInstallation {
enabled = false
}

ignoredBuildTypes = ["debug"]
}

dependencies {
implementation project(':base')

Expand Down Expand Up @@ -94,9 +109,11 @@ dependencies {
implementation libs.koin.annotations
implementation libs.kotlinx.coroutines.android
implementation libs.kotlinx.serialization.json
implementation libs.sentry.android
implementation libs.timber
implementation libs.treessence


testImplementation libs.junit
androidTestImplementation libs.androidx.test.espresso.core
androidTestImplementation libs.androidx.test.junit
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths_shared" />
</provider>

<provider
android:name="io.sentry.android.core.SentryInitProvider"
android:authorities="${applicationId}.SentryInitProvider"
tools:node="remove" />

<provider
android:name="io.sentry.android.core.SentryPerformanceProvider"
android:authorities="${applicationId}.SentryPerformanceProvider"
tools:node="remove" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ package com.studio4plus.homerplayer2.app

import android.app.Application
import com.studio4plus.homerplayer2.BuildConfig
import com.studio4plus.homerplayer2.R
import com.studio4plus.homerplayer2.logging.FileLoggerTreeProvider
import io.sentry.android.core.SentryAndroid
import org.koin.android.ext.android.inject
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import org.koin.ksp.generated.*
import org.koin.ksp.generated.module
import timber.log.Timber

class HomerPlayerApp : Application() {

override fun onCreate() {
super.onCreate()
initCrashReporting()

startKoin {
androidContext(this@HomerPlayerApp)
Expand All @@ -49,4 +52,19 @@ class HomerPlayerApp : Application() {
val fileLoggerProvider: FileLoggerTreeProvider by inject()
Timber.plant(fileLoggerProvider())
}

// Try to share Sentry configuration between app and kiosksetup.
private fun initCrashReporting() {
if (!BuildConfig.DEBUG) {
SentryAndroid.init(this) { options ->
options.dsn = getString(R.string.sentry_dsn)
options.isEnableAppLifecycleBreadcrumbs = true
options.isEnableAppComponentBreadcrumbs = true

options.isEnableUserInteractionBreadcrumbs = false
options.isEnableActivityLifecycleBreadcrumbs = false
options.isEnableNetworkEventBreadcrumbs = false
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import org.koin.android.annotation.KoinViewModel
import kotlin.properties.Delegates

@KoinViewModel
class OnboardingSpeechViewModel(
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ kotlin = '1.9.21'
kotlinx-coroutines = '1.7.3'
media3 = '1.2.1'
room = '2.6.1'
sentry-android = '7.6.0'

[libraries]

Expand Down Expand Up @@ -50,6 +51,8 @@ kotlinx-coroutines-android = { module = 'org.jetbrains.kotlinx:kotlinx-coroutine

kotlinx-serialization-json = { module = 'org.jetbrains.kotlinx:kotlinx-serialization-json', version = '1.5.1' }

sentry-android = { module = 'io.sentry:sentry-android', version.ref = 'sentry-android' }

timber = 'com.jakewharton.timber:timber:5.0.1'
treessence = 'com.github.bastienpaulfr:Treessence:1.1.2'

Expand All @@ -62,4 +65,5 @@ android-application = { id = "com.android.application", version.ref = "android-g
android-library = { id = "com.android.library", version.ref = "android-gradle-plugin" }
kotlin-jvm = { id = 'org.jetbrains.kotlin.android', version.ref = 'kotlin' }
kotlin-serialization = { id = 'org.jetbrains.kotlin.plugin.serialization', version.ref = 'kotlin' }
ksp = 'com.google.devtools.ksp:1.9.21-1.0.15'
ksp = 'com.google.devtools.ksp:1.9.21-1.0.15'
sentry = 'io.sentry.android.gradle:4.3.1'
4 changes: 3 additions & 1 deletion kiosksetup/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.ksp)
alias(libs.plugins.sentry)
}

android {
Expand All @@ -50,7 +51,7 @@ android {

buildTypes {
release {
isMinifyEnabled = false
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand Down Expand Up @@ -102,6 +103,7 @@ dependencies {
implementation(libs.koin.androidx.compose)
implementation(libs.koin.annotations)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.sentry.android)

testImplementation(libs.junit)
}
Expand Down
13 changes: 12 additions & 1 deletion kiosksetup/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
~ SOFTWARE.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
Expand Down Expand Up @@ -83,6 +84,16 @@
<action android:name="android.app.action.DEVICE_OWNER_CHANGED" />
</intent-filter>
</receiver>

<provider
android:name="io.sentry.android.core.SentryInitProvider"
android:authorities="${applicationId}.SentryInitProvider"
tools:node="remove" />

<provider
android:name="io.sentry.android.core.SentryPerformanceProvider"
android:authorities="${applicationId}.SentryPerformanceProvider"
tools:node="remove" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.studio4plus.homerplayer2.kiosk

import android.app.Application
import io.sentry.android.core.SentryAndroid
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.GlobalContext.startKoin
import org.koin.ksp.generated.*
Expand All @@ -33,10 +34,25 @@ class KioskSetupApp : Application() {

override fun onCreate() {
super.onCreate()
initCrashReporting()

startKoin {
androidContext(this@KioskSetupApp)
modules(AppModule().module)
}
}

private fun initCrashReporting() {
if (!BuildConfig.DEBUG) {
SentryAndroid.init(this) { options ->
options.dsn = getString(R.string.sentry_dsn)
options.isEnableAppLifecycleBreadcrumbs = true
options.isEnableAppComponentBreadcrumbs = true

options.isEnableUserInteractionBreadcrumbs = false
options.isEnableActivityLifecycleBreadcrumbs = false
options.isEnableNetworkEventBreadcrumbs = false
}
}
}
}

0 comments on commit 2682ab0

Please sign in to comment.