Skip to content

Commit

Permalink
Move to new Crashlytics SDK (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern authored May 11, 2020
1 parent f3c0a83 commit 82d6479
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ google-services.json
.project
.settings
.classpath
.vscode
1 change: 0 additions & 1 deletion auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ allprojects {
mavenLocal()
jcenter()
google()
maven { url 'https://maven.fabric.io/public' }
}
}

Expand Down
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ buildscript {
google()
jcenter()
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72'

classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.firebase:perf-plugin:1.3.1'
classpath 'io.fabric.tools:gradle:1.31.2'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.0'
}
}

Expand All @@ -25,7 +24,6 @@ allprojects {
//mavenLocal() must be listed at the top to facilitate testing
mavenLocal()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}

def isNonStable = { candidate ->
Expand Down
4 changes: 2 additions & 2 deletions crash/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.crashlytics'

check.dependsOn 'assembleDebugAndroidTest'

Expand Down Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation project(":internal:chooserx")
implementation 'com.google.android.material:material:1.1.0'

implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.firebase:firebase-crashlytics:17.0.0'

// For an optimal experience using Crashlytics, add the Firebase SDK
// for Google Analytics. This is recommended, but not required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.util.Log;
import android.view.View;

import com.crashlytics.android.Crashlytics;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.google.samples.quickstart.crash.databinding.ActivityMainBinding;

/**
Expand All @@ -38,30 +38,33 @@
public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";
private FirebaseCrashlytics mCrashlytics;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

mCrashlytics = FirebaseCrashlytics.getInstance();

// Log the onCreate event, this will also be printed in logcat
Crashlytics.log(Log.VERBOSE, TAG, "onCreate");
mCrashlytics.log("onCreate");

// Add some custom values and identifiers to be included in crash reports
Crashlytics.setInt("MeaningOfLife", 42);
Crashlytics.setString("LastUIAction", "Test value");
Crashlytics.setUserIdentifier("123456789");
mCrashlytics.setCustomKey("MeaningOfLife", 42);
mCrashlytics.setCustomKey("LastUIAction", "Test value");
mCrashlytics.setUserId("123456789");

// Report a non-fatal exception, for demonstration purposes
Crashlytics.logException(new Exception("Non-fatal exception: something went wrong!"));
mCrashlytics.recordException(new Exception("Non-fatal exception: something went wrong!"));

// Button that causes NullPointerException to be thrown.
binding.crashButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Log that crash button was clicked.
Crashlytics.log(Log.INFO, TAG, "Crash button clicked.");
mCrashlytics.log("Crash button clicked.");

// If catchCrashCheckBox is checked catch the exception and report it using
// logException(), Otherwise throw the exception and let Crashlytics automatically
Expand All @@ -71,8 +74,8 @@ public void onClick(View v) {
throw new NullPointerException();
} catch (NullPointerException ex) {
// [START crashlytics_log_and_report]
Crashlytics.log(Log.ERROR, TAG, "NPE caught!");
Crashlytics.logException(ex);
mCrashlytics.log("NPE caught!");
mCrashlytics.recordException(ex);
// [END crashlytics_log_and_report]
}
} else {
Expand All @@ -83,7 +86,7 @@ public void onClick(View v) {

// Log that the Activity was created.
// [START crashlytics_log_event]
Crashlytics.log("Activity created");
mCrashlytics.log("Activity created");
// [END crashlytics_log_event]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.google.samples.quickstart.crash.kotlin

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.util.Log
import com.crashlytics.android.Crashlytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.samples.quickstart.crash.databinding.ActivityMainBinding

/**
Expand All @@ -19,26 +18,30 @@ import com.google.samples.quickstart.crash.databinding.ActivityMainBinding
*/
class MainActivity : AppCompatActivity() {

private lateinit var crashlytics: FirebaseCrashlytics;

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

crashlytics = FirebaseCrashlytics.getInstance()

// Log the onCreate event, this will also be printed in logcat
Crashlytics.log(Log.VERBOSE, TAG, "onCreate")
crashlytics.log("onCreate")

// Add some custom values and identifiers to be included in crash reports
Crashlytics.setInt("MeaningOfLife", 42)
Crashlytics.setString("LastUIAction", "Test value")
Crashlytics.setUserIdentifier("123456789")
crashlytics.setCustomKey("MeaningOfLife", 42)
crashlytics.setCustomKey("LastUIAction", "Test value")
crashlytics.setUserId("123456789")

// Report a non-fatal exception, for demonstration purposes
Crashlytics.logException(Exception("Non-fatal exception: something went wrong!"))
crashlytics.recordException(Exception("Non-fatal exception: something went wrong!"))

// Button that causes NullPointerException to be thrown.
binding.crashButton.setOnClickListener {
// Log that crash button was clicked.
Crashlytics.log(Log.INFO, TAG, "Crash button clicked.")
crashlytics.log("Crash button clicked.")

// If catchCrashCheckBox is checked catch the exception and report it using
// logException(), Otherwise throw the exception and let Crashlytics automatically
Expand All @@ -48,8 +51,8 @@ class MainActivity : AppCompatActivity() {
throw NullPointerException()
} catch (ex: NullPointerException) {
// [START crashlytics_log_and_report]
Crashlytics.log(Log.ERROR, TAG, "NPE caught!")
Crashlytics.logException(ex)
crashlytics.log( "NPE caught!")
crashlytics.recordException(ex)
// [END crashlytics_log_and_report]
}
} else {
Expand All @@ -59,12 +62,11 @@ class MainActivity : AppCompatActivity() {

// Log that the Activity was created.
// [START crashlytics_log_event]
Crashlytics.log("Activity created")
crashlytics.log("Activity created")
// [END crashlytics_log_event]
}

companion object {

private const val TAG = "MainActivity"
}
}
3 changes: 1 addition & 2 deletions crash/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ buildscript {
jcenter()
mavenLocal()
google()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.2'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72'
}
}
Expand Down

0 comments on commit 82d6479

Please sign in to comment.