From 384c50b53c4d4381dd2e177b44595a31f13043cf Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Wed, 16 Oct 2024 08:10:32 +0200 Subject: [PATCH] Initialize Sentry --- .github/workflows/android.yml | 14 ++++++------ app/build.gradle.kts | 22 +++++++++++++++++++ app/src/main/AndroidManifest.xml | 14 ++++++++++++ .../swisstransfer/ui/MainApplication.kt | 13 +++++++++++ gradle/libs.versions.toml | 4 ++++ 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index a0bc37711..3b462a2d9 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -21,20 +21,20 @@ jobs: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.12.1 with: - access_token: ${{ github.token }} + access_token: ${ { github.token } } - name: Checkout the code uses: actions/checkout@v4.1.7 with: - token: ${{ github.token }} + token: ${ { github.token } } submodules: recursive - # Setup Gradle and run Build + # Setup Gradle and Run tests - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Build with Gradle - run: ./gradlew build - # Run tests - - name: Run Unit tests + - name: Clean gradle cache + run: ./gradlew clean + + - name: Run unit tests run: ./gradlew testDebugUnitTest --stacktrace diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 19b93c19e..830b432fe 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.compose.compiler) alias(libs.plugins.kapt) alias(libs.plugins.hilt) + alias(libs.plugins.sentry) kotlin("plugin.serialization") version libs.versions.kotlin } @@ -63,6 +64,26 @@ kapt { correctErrorTypes = true } +sentry { + // Enables or disables the automatic upload of mapping files + // during a build. If you disable this, you'll need to manually + // upload the mapping files with sentry-cli when you do a release. + // Default is enabled. + autoUploadProguardMapping = true + + // Disables or enables the automatic configuration of Native Symbols + // for Sentry. This executes sentry-cli automatically so + // you don't need to do it manually. + // Default is disabled. + uploadNativeSymbols = true + + // Does or doesn't include the source code of native code for Sentry. + // This executes sentry-cli with the --include-sources param. automatically so + // you don't need to do it manually. + // Default is disabled. + includeNativeSources = true +} + dependencies { implementation(kotlin("reflect")) @@ -79,6 +100,7 @@ dependencies { implementation(libs.compose.material3.adaptative.navigation) implementation(libs.navigation.compose) implementation(libs.androidx.constraintlayout.compose) + implementation(libs.sentry.android) implementation(libs.androidx.adaptive) implementation(libs.androidx.adaptive.layout) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dc91f9387..2f0e46599 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,10 +31,24 @@ android:theme="@style/Theme.AndroidSwissTransfer" android:usesCleartextTraffic="false" tools:targetApi="31"> + + + + + + + + diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt index ca2e2f661..e5f990138 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt @@ -19,7 +19,12 @@ package com.infomaniak.swisstransfer.ui import android.app.Application import com.infomaniak.multiplatform_swisstransfer.SwissTransferInjection +import com.infomaniak.swisstransfer.BuildConfig import dagger.hilt.android.HiltAndroidApp +import io.sentry.SentryEvent +import io.sentry.SentryOptions +import io.sentry.android.core.SentryAndroid +import io.sentry.android.core.SentryAndroidOptions import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import javax.inject.Inject @@ -36,5 +41,13 @@ class MainApplication : Application() { override fun onCreate() { super.onCreate() globalCoroutineScope.launch { swissTransferInjection.loadDefaultAccount() } + + SentryAndroid.init(this) { options: SentryAndroidOptions -> + // register the callback as an option + options.beforeSend = SentryOptions.BeforeSendCallback { event: SentryEvent?, _: Any? -> + //if the application is in debug mode discard the events + if (BuildConfig.DEBUG) null else event + } + } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5c95d1969..e42b8803c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,8 @@ lifecycleRuntimeKtx = "2.8.6" navigation = "2.8.1" serialization = "1.7.1" swisstransfer = "0.1.1" +sentry = "4.12.0" +sentry-android = "7.15.0" [libraries] androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } @@ -38,11 +40,13 @@ hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", ve kotlinx-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" } navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigation" } swisstransfer-core = { module = "com.github.Infomaniak.multiplatform-SwissTransfer:STCore", version.ref = "swisstransfer" } +sentry-android = { module = "io.sentry:sentry-android", version.ref = "sentry-android" } # Tests androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } junit = { group = "junit", name = "junit", version.ref = "junit" } [plugins] +sentry = { id = "io.sentry.android.gradle", version.ref = "sentry" } android-application = { id = "com.android.application", version.ref = "agp" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }