From 77cbfdd90143308946f6bbf390b7a27cb89c909d Mon Sep 17 00:00:00 2001 From: Dmytro Ponomarenko Date: Mon, 20 May 2024 23:54:34 +0300 Subject: [PATCH 1/2] Added Crashlytics to release build. --- app/build.gradle | 22 +++---- app/src/main/AndroidManifest.xml | 2 +- .../dimowner/audiorecorder/ARApplication.kt | 64 ++++++++++++++++--- build.gradle | 4 +- 4 files changed, 70 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4ffde15f..8770b499 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,8 +2,8 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-kapt' -//apply plugin: 'com.google.firebase.crashlytics' -//apply plugin: 'com.google.gms.google-services' +apply plugin: 'com.google.firebase.crashlytics' +apply plugin: 'com.google.gms.google-services' android { namespace 'com.dimowner.audiorecorder' @@ -45,9 +45,9 @@ android { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' -// firebaseCrashlytics { -// mappingFileUploadEnabled true -// } + firebaseCrashlytics { + mappingFileUploadEnabled true + } } debug { minifyEnabled false @@ -108,10 +108,10 @@ dependencies { testImplementation("junit:junit:4.13.2") testImplementation("io.mockk:mockk:1.13.10") -// // Import the BoM for the Firebase platform -// implementation platform('com.google.firebase:firebase-bom:26.1.0') -// // Declare the dependencies for the Crashlytics and Analytics libraries -// // When using the BoM, you don't specify versions in Firebase library dependencies -// implementation 'com.google.firebase:firebase-crashlytics' -// implementation 'com.google.firebase:firebase-analytics' + // Import the BoM for the Firebase platform + implementation platform('com.google.firebase:firebase-bom:33.0.0') + // Declare the dependencies for the Crashlytics and Analytics libraries + // When using the BoM, you don't specify versions in Firebase library dependencies + implementation 'com.google.firebase:firebase-crashlytics' + implementation 'com.google.firebase:firebase-analytics' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7de796d5..165368f5 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,7 +5,7 @@ - + { + Timber.plant(object : DebugTree() { + override fun createStackElementTag(element: StackTraceElement): String? { + return super.createStackElementTag(element) + ":" + element.lineNumber + } + }) + } + else -> { + Timber.plant(CrashlyticsTree()) + } } override fun onTerminate() { @@ -173,4 +184,41 @@ class ARApplication : Application() { val longWaveformSampleCount: Int get() = (AppConstants.WAVEFORM_WIDTH * screenWidthDp).toInt() } -} \ No newline at end of file +} + +class CrashlyticsTree: Timber.Tree() { + + private val crashlytics = FirebaseCrashlytics.getInstance() + + override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { + + if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) { + return + } + + if (BuildConfig.DEBUG) { + crashlytics.setCrashlyticsCollectionEnabled(false) + return + } + + crashlytics.setCustomKey(CRASHLYTICS_KEY_PRIORITY, priority) + + if (tag != null) { + crashlytics.setCustomKey(CRASHLYTICS_KEY_TAG, tag) + } + crashlytics.setCustomKey(CRASHLYTICS_KEY_MESSAGE, message) + + if (t == null) { + crashlytics.recordException(Exception(message)) + } + else { + crashlytics.recordException(t) + } + } + + companion object { + private const val CRASHLYTICS_KEY_PRIORITY = "priority" + private const val CRASHLYTICS_KEY_TAG = "tag" + private const val CRASHLYTICS_KEY_MESSAGE = "message" + } +} diff --git a/build.gradle b/build.gradle index e72bd1a5..14406543 100755 --- a/build.gradle +++ b/build.gradle @@ -10,8 +10,8 @@ buildscript { classpath 'com.android.tools.build:gradle:8.4.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" -// classpath 'com.google.gms:google-services:4.3.10' -// classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1' + classpath 'com.google.gms:google-services:4.4.1' + classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.1' } } From 3ac8d1798e00dddd431b99a9be78080f8923e5ee Mon Sep 17 00:00:00 2001 From: Dmytro Ponomarenko Date: Tue, 21 May 2024 23:34:20 +0300 Subject: [PATCH 2/2] Added advertising ID permission that required by Google Play. --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 8770b499..7a31cba0 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,7 @@ android { applicationId "com.dimowner.audiorecorder" minSdkVersion 23 targetSdkVersion 34 - versionCode 935 + versionCode 936 versionName "0.9.99" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 165368f5..41f406bd 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ +