Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Timber + Crashlytics →
A match made in
heaven
DAMIAN MARUŠIĆ
MAIN TOPICS
• Timber
• Crashlytics
• App crash handler
WHAT DO WE WANT ?
• Development - logging to logcat
• Production - crash reporting to Crashlytics
TIMBER
• Utility on top of Android's normal Log class
• by Jake Wharton
Timber.plant(new Timber.DebugTree());
Timber.d(...)
Timber.i(...)
Timber.v(...)
Timber.e(...)
Timber.w(...)
Timber.wtf(...)
CRASHLYTICS
• Crash reporting tool
• Automatic and manual crash reports
• Stack trace
• Android version
• Device model
• e...
CRASH REPORTING TREE
private static class CrashReportingTree extends Timber.Tree {



@Override

protected void log(int pr...
CRASH REPORTING TREE
@Override

public void onCreate() {

super.onCreate();
CrashlyticsCore crashlyticsCore = new Crashlyt...
USAGE
try {
...
} catch (Exception e) {

Timber.e(e, "Failure in " + getClass().getSimpleName());

}
APP CRASH HANDLER
• No more ugly system dialogs
• Restart app
• Simple configuration
• by Square
APP CRASH HANDLER
→
APP CRASH HANDLER EXAMPLE
public class AppCrashHandler implements Thread.UncaughtExceptionHandler {



private Activity li...
APP CRASH HANDLER EXAMPLE
@Override

public void onCreate() {

super.onCreate();

Thread.setDefaultUncaughtExceptionHandle...
Thank you!
DAMIAN.MARUSIC@INFINUM.HR
Visit infinum.co or find us on social networks:
infinum.co infinumco infinumco infinum
REFERENCES
• Timber - https://github.com/JakeWharton/timber
• Square’s approach to Android crashes - https://vimeo.com/
14...
Infinum Android Talks #15 - Timber + Crashlytics -> A match made in heaven
Upcoming SlideShare
Loading in …5
×

Infinum Android Talks #15 - Timber + Crashlytics -> A match made in heaven

1,045 views

Published on

In this talk we'll show you how to implement efficient logging during the development phase and seamless crash reporting when your app is in production. All this with as little configuration as possible. If crashes are something you want your users to be unaware of, we'll demonstrate how to achieve it with Square's app crash handler.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Infinum Android Talks #15 - Timber + Crashlytics -> A match made in heaven

  1. 1. Timber + Crashlytics → A match made in heaven DAMIAN MARUŠIĆ
  2. 2. MAIN TOPICS • Timber • Crashlytics • App crash handler
  3. 3. WHAT DO WE WANT ? • Development - logging to logcat • Production - crash reporting to Crashlytics
  4. 4. TIMBER • Utility on top of Android's normal Log class • by Jake Wharton
  5. 5. Timber.plant(new Timber.DebugTree()); Timber.d(...) Timber.i(...) Timber.v(...) Timber.e(...) Timber.w(...) Timber.wtf(...)
  6. 6. CRASHLYTICS • Crash reporting tool • Automatic and manual crash reports • Stack trace • Android version • Device model • etc.
  7. 7. CRASH REPORTING TREE private static class CrashReportingTree extends Timber.Tree {
 
 @Override
 protected void log(int priority, String tag, String message, Throwable t) {
 if (priority == Log.VERBOSE || priority == Log.DEBUG) {
 return;
 }
 
 // will write to the crash report but NOT to logcat
 Crashlytics.log(message);
 
 if (t != null) {
 Crashlytics.logException(t);
 }
 }
 }
  8. 8. CRASH REPORTING TREE @Override
 public void onCreate() {
 super.onCreate(); CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder() .disabled(BuildConfig.DEBUG).build(); Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).build()); if (BuildConfig.DEBUG) {
 Timber.plant(new Timber.DebugTree());
 } else {
 Timber.plant(new CrashReportingTree());
 }
 }
  9. 9. USAGE try { ... } catch (Exception e) {
 Timber.e(e, "Failure in " + getClass().getSimpleName());
 }
  10. 10. APP CRASH HANDLER • No more ugly system dialogs • Restart app • Simple configuration • by Square
  11. 11. APP CRASH HANDLER →
  12. 12. APP CRASH HANDLER EXAMPLE public class AppCrashHandler implements Thread.UncaughtExceptionHandler {
 
 private Activity liveActivity;
 
 public AppCrashHandler(Application application) {
 application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { 
 @Override
 public void onActivityResumed(Activity activity) {
 liveActivity = activity;
 }
 @Override
 public void onActivityPaused(Activity activity) {
 liveActivity = null;
 }
 });
 }
 @Override
 public void uncaughtException(Thread thread, Throwable ex) {
 if(liveActivity != null){
 Intent intent = new Intent(getApplicationContext(), MainActivity.class);
 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 liveActivity.finish();
 liveActivity.startActivity(intent);
 }
 
 System.exit(0);
 }
 }
  13. 13. APP CRASH HANDLER EXAMPLE @Override
 public void onCreate() {
 super.onCreate();
 Thread.setDefaultUncaughtExceptionHandler(new AppCrashHandler(this));
 }
  14. 14. Thank you! DAMIAN.MARUSIC@INFINUM.HR Visit infinum.co or find us on social networks: infinum.co infinumco infinumco infinum
  15. 15. REFERENCES • Timber - https://github.com/JakeWharton/timber • Square’s approach to Android crashes - https://vimeo.com/ 145042944 • Željko’s crash handler lib - https://github.com/zplesac/ android-crash-handler

×