Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Firebase Crashlytics. From this branch the Audio Recorder published to Google Play #119

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions 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-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'
Expand All @@ -12,7 +12,7 @@ android {
applicationId "com.dimowner.audiorecorder"
minSdkVersion 23
targetSdkVersion 34
versionCode 935
versionCode 936
versionName "0.9.99"
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- <uses-permission android:name="android.permission.INTERNET" />-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"
Expand Down
64 changes: 56 additions & 8 deletions app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,23 @@ import android.os.Handler
import android.telephony.PhoneStateListener
import android.telephony.TelephonyCallback
import android.telephony.TelephonyManager
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import com.dimowner.audiorecorder.util.AndroidUtils
import timber.log.Timber
import timber.log.Timber.DebugTree
import com.google.firebase.FirebaseApp
import com.google.firebase.crashlytics.FirebaseCrashlytics


//import com.google.firebase.FirebaseApp;
class ARApplication : Application() {

private var audioOutputChangeReceiver: AudioOutputChangeReceiver? = null
private var rebootReceiver: RebootReceiver? = null

override fun onCreate() {
if (BuildConfig.DEBUG) {
//Timber initialization
Timber.plant(DebugTree())
}
super.onCreate()
initTimber()
PACKAGE_NAME = applicationContext.packageName
applicationHandler = Handler(applicationContext.mainLooper)
screenWidthDp = AndroidUtils.pxToDp(
Expand All @@ -74,7 +72,20 @@ class ARApplication : Application() {
} catch (e: Exception) {
Timber.e(e)
}
// FirebaseApp.initializeApp(this);
FirebaseApp.initializeApp(this)
}

private fun initTimber() = when {
BuildConfig.DEBUG -> {
Timber.plant(object : DebugTree() {
override fun createStackElementTag(element: StackTraceElement): String? {
return super.createStackElementTag(element) + ":" + element.lineNumber
}
})
}
else -> {
Timber.plant(CrashlyticsTree())
}
}

override fun onTerminate() {
Expand Down Expand Up @@ -201,4 +212,41 @@ class ARApplication : Application() {
val longWaveformSampleCount: Int
get() = (AppConstants.WAVEFORM_WIDTH * screenWidthDp).toInt()
}
}
}

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"
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down