Skip to content

Commit

Permalink
Merge pull request #22 from Qase/use-firebase-crashlytics
Browse files Browse the repository at this point in the history
Use firebase crashlytics
  • Loading branch information
neubami94 authored Mar 23, 2021
2 parents 44cf560 + 15dd337 commit c715eab
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 49 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ val androidBundle = LoggerBundle(LogLevel.INFO)
Log.addLogger(AndroidLogger(androidBundle))

//default log level is warn
Fabric.with(this, Crashlytics())
//apply plugins google-services and firebase.crashlytics, copy google-services.json in app/ directory
//download google-services.json from https://console.firebase.google.com/u/0/project/{project_id}/settings/general/android:{project_package}
//add these two lines in app/build.gradle
// apply plugin: 'com.google.gms.google-services'
// apply plugin: 'com.google.firebase.crashlytics'
Log.addLogger(CrashlyticsLogger())

//Every LogBundles has ton of options, see javadoc for more
Expand Down
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/build
.idea
*.iml
*.iml
google-services.json
14 changes: 4 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'

repositories {
maven { url 'https://maven.fabric.io/public' }
}

android {
compileSdkVersion 27
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "quanti.com.kotlinlog3"
Expand All @@ -32,7 +29,7 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// library - select one - either local or maven
Expand All @@ -42,9 +39,6 @@ dependencies {
// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.2@aar') {
transitive = true
}
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
Expand Down
39 changes: 39 additions & 0 deletions app/google-services.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "1234",
"project_id": "kotlinloggerexample",
"storage_bucket": "kotlinloggertest.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1234:android:abcdef123456",
"android_client_info": {
"package_name": "quanti.com.kotlinlog3"
}
},
"oauth_client": [
{
"client_id": "1234-abcdef123456.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "abcdef123456"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1234-abcdef123456.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="95f39747d5544e8f30d7cbd0cc36e6781b3a12e0"
/>
</application>

</manifest>
15 changes: 7 additions & 8 deletions app/src/main/java/quanti/com/kotlinlog3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import android.content.Context
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.SystemClock
import android.support.annotation.IdRes
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.*
import com.crashlytics.android.Crashlytics
import io.fabric.sdk.android.Fabric
import androidx.annotation.IdRes
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers
import quanti.com.kotlinlog.Log
Expand Down Expand Up @@ -111,7 +109,8 @@ class MainActivity : AppCompatActivity(), RadioGroup.OnCheckedChangeListener, IS
Log.useUncheckedErrorHandler()
Log.addLogger(AndroidLogger())

Fabric.with(this, Crashlytics())
// No need initialize Firebase Crashlytics. It is initialized automatically by
// com.google.firebase.crashlytics plugin and google-services.json
Log.addLogger(CrashlyticsLogger())

switchLogger_clicked(null)
Expand Down
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ buildscript {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'io.fabric.tools:gradle:1.+'

classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.1'
}
}

Expand All @@ -28,7 +27,6 @@ allprojects {
jcenter()
maven { url 'https://jitpack.io' }
maven { url "https://maven.google.com" }
maven { url 'https://maven.fabric.io/public' }
}
}

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
16 changes: 5 additions & 11 deletions kotlinlog/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
//apply plugin: 'io.fabric'

group = 'com.qithub.qase'

repositories {
maven { url 'https://maven.fabric.io/public' }
}

android {
compileSdkVersion 27
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 16
targetSdkVersion 27
versionCode 3
versionName "2.2.3"
buildConfigField 'int', 'VERSION_CODE', "$versionCode"
buildConfigField 'String', 'VERSION_NAME', "\"$versionName\""
consumerProguardFile('proguard-rules.pro')
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -55,7 +52,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-annotations:28.0.0'

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0'
Expand All @@ -69,10 +66,7 @@ dependencies {
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'


implementation('com.crashlytics.sdk.android:crashlytics:2.9.2@aar') {
transitive = true
}
implementation 'com.google.firebase:firebase-crashlytics-ktx:17.4.0'

// Testing-only dependencies
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package quanti.com.kotlinlog.crashlytics

import com.crashlytics.android.Crashlytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import quanti.com.kotlinlog.base.ILogger
import quanti.com.kotlinlog.base.LogLevel
import quanti.com.kotlinlog.base.LoggerBundle
Expand All @@ -19,14 +19,16 @@ class CrashlyticsLogger(
override fun getMinimalLoggingLevel(): Int = bun.minimalLogLevel

override fun log(androidLogLevel: Int, tag: String, methodName: String, text: String) {
Crashlytics.log("$tag $methodName $text")
FirebaseCrashlytics.getInstance().log("$tag $methodName $text")
}

override fun logSync(androidLogLevel: Int, tag: String, methodName: String, text: String) = log(androidLogLevel, tag, methodName, text)

override fun logThrowable(androidLogLevel: Int, tag: String, methodName: String, text: String, t: Throwable) {
Crashlytics.log("$tag $methodName $text")
Crashlytics.logException(t)
FirebaseCrashlytics.getInstance().apply {
log("$tag $methodName $text")
recordException(t)
}
}

override fun cleanResources() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package quanti.com.kotlinlog.file

import android.support.v4.content.FileProvider
import androidx.core.content.FileProvider

class LogFileProvider : FileProvider()
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.app.Dialog
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.app.AlertDialog
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package quanti.com.kotlinlog.utils
import android.content.Context
import android.media.MediaScannerConnection
import android.os.Environment
import android.support.v4.content.FileProvider
import androidx.core.content.FileProvider
import quanti.com.kotlinlog.Log.Companion.i
import quanti.com.kotlinlog.file.file.MetadataFile
import quanti.com.kotlinlog.forceWrite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package quanti.com.kotlinlog.utils

import android.content.Context
import android.content.pm.PackageManager
import android.support.v4.content.ContextCompat
import androidx.core.content.ContextCompat
import java.util.jar.Manifest

/**
Expand Down

0 comments on commit c715eab

Please sign in to comment.