From ff55105fabc984df36dd011313834a976a071c66 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Thu, 19 Apr 2018 17:01:00 +0200 Subject: [PATCH] Issue #9: Add crash reporting via Mozilla's sentry instance. --- app/build.gradle | 17 +++++++++++++- app/src/main/AndroidManifest.xml | 7 +++++- .../java/mozilla/fenix/FenixApplication.kt | 23 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/mozilla/fenix/FenixApplication.kt diff --git a/app/build.gradle b/app/build.gradle index 2652a5be1..8ea0d90bc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,13 +29,28 @@ android { } dependencies { + implementation 'io.sentry:sentry-android:1.7.3' + implementation 'com.android.support:appcompat-v7:27.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' - implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' } + +// ------------------------------------------------------------------------------------------------- +// -- Sentry +// ------------------------------------------------------------------------------------------------- + +android.applicationVariants.all { + try { + def token = new File("${rootDir}/.sentry").text.trim() + buildConfigField 'String', 'SENTRY_TOKEN', '"' + token + '"' + } catch (FileNotFoundException ignored) { + buildConfigField 'String', 'SENTRY_TOKEN', 'null' + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c05565f60..3b2911df1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,13 +2,17 @@ + + + + android:theme="@style/AppTheme" + android:name=".FenixApplication"> @@ -16,6 +20,7 @@ + \ No newline at end of file diff --git a/app/src/main/java/mozilla/fenix/FenixApplication.kt b/app/src/main/java/mozilla/fenix/FenixApplication.kt new file mode 100644 index 000000000..e925481e5 --- /dev/null +++ b/app/src/main/java/mozilla/fenix/FenixApplication.kt @@ -0,0 +1,23 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package mozilla.fenix + +import android.app.Application +import io.sentry.Sentry +import io.sentry.android.AndroidSentryClientFactory + +class FenixApplication : Application() { + override fun onCreate() { + super.onCreate() + + initializeCrashReporting() + } + + private fun initializeCrashReporting() { + if (BuildConfig.SENTRY_TOKEN != null) { + Sentry.init(BuildConfig.SENTRY_TOKEN, AndroidSentryClientFactory(this)) + } + } +}