Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unlock Better Version of Your Mobile App (By: A...

Unlock Better Version of Your Mobile App (By: Abid Jamil) - DevFest 2022

Talk by Abid Jamil (https://www.linkedin.com/in/abidjamil) at DevFest Lahore 2022 by GDG Lahore.

GDG Lahore

December 17, 2022
Tweet

More Decks by GDG Lahore

Other Decks in Programming

Transcript

  1. 50% Stability & bugs When leaving a 1 star review,

    50% of the time the user mentions the app stability and bugs Google analysis on Play reviews, top 10 English speaking countries, last 365 days of reviews
  2. Step 1: Add the Crashlytics SDK to your ap p

    In your module (app-level) Gradle fi le (usually <project>/<app-module>/build.gradle), add the dependency for the Crashlytics Android library.
  3. In your root-level (project-level) Gradle fi le (<project>/build.gradle), add the

    Crashlytics Gradle plugin as a buildscript dependency: Step 2: Add the Crashlytics Gradle plugin to your ap p
  4. To give yourself more context for the events leading up

    to a crash, you can add custom Crashlytics logs to your app
  5. To diagnose an issue, it’s often helpful to know which

    of your users experienced a given crash. Crashlytics includes a way to anonymously identify users in your crash reports.
  6. Set user identi fi er s Add Custom Log s

    val crashlytics = Firebase.crashlytic s crashlytics.setCustomKeys { key("device", "android" ) key("email", user.email ) key("id", user.id ) key("name", user.name ) key("phone", user.phone ) } Add Custom Key s
  7. public class MyHandler implements Thread.UncaughtExceptionHandler { private final Thread.UncaughtExceptionHandler mPriorExceptionHandler;

    public MyHandler(Thread.UncaughtExceptionHandler prior) { mPriorExceptionHandler = prior; } @Override public void uncaughtException(Thread thread, Throwable throwable) { // Deal with throwable here if (mPriorExceptionHandler != null) { mPriorExceptionHandler.uncaughtException(thread, throwable); } } }
  8. 60% Speed, design & usability When leaving a 5 star

    review, 60% of the time the user mentions the speed, design or usability Google analysis on Play reviews, top 10 English speaking countries, last 365 days of reviews
  9. Firebase Performance Monitoring • Runs in production • Negligible overhead

    • Automatic and Custom traces • Automatic HTTP/S traffic metrics
  10. Trace • A report for a period of time with

    a well-defined beginning and end • Nominally has a duration • Also may contain "counters" for performance-related events during the trace
  11. Automatic Traces - no coding necessary! • App Start (cold)

    • Time in foreground • Time in background
  12. Counters • Associate a string/count value to a Trace •

    Typically better to measure ratios than absolute values • Abs value if you want to compare similar counters between traces cache_hit++ cache_miss++ dropped_frames += 10
  13. Implement Lifecycle Callbacks public class PerfLifecycleCallbacks implements Application.ActivityLifecycleCallbacks { private

    static final PerfLifecycleCallbacks instance = new PerfLifecycleCallbacks() ; private PerfLifecycleCallbacks() { } public static PerfLifecycleCallbacks getInstance() { return instance ; } }
  14. Implement Lifecyclecallbacks private final HashMap<Activity, Trace> traces = new HashMap<>()

    ; @Overrid e public void onActivityStarted(Activity activity) { String name = activity.getClass().getSimpleName() ; Trace trace = FirebasePerformance.startTrace(name) ; traces.put(activity, trace) ; } @Overrid e public void onActivityStopped(Activity activity) { Trace trace = traces.remove(activity) ; trace.stop() ; }
  15. Use Annotations import com.google. fi rebase.perf.FirebasePerformance ; import com.google. fi

    rebase.perf.metrics.AddTrace ; // Add the `@AddTrace` annotation above the method you want to trac e @AddTrace(name = "onCreateTrace", enabled = true /* optional */ ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) }
  16. Use Annotations val cache = ItemCache( ) val myTrace =

    Firebase.performance.newTrace("test_trace" ) myTrace.start( ) val item = cache.fetch("item" ) if (item != null) { myTrace.incrementMetric("item_cache_hit", 1 ) } else { myTrace.incrementMetric("item_cache_miss", 1 ) } myTrace.stop( )
  17. Android Vitals - get clues for what to measure •

    New in the Google Play Console: • Performance-related stats • Slow rendering (jank) • Frozen frames
  18. Automatic HTTP/S transaction metrics • Response time • Payload size

    • Success rate • URL pattern yourcdn.com/*.jpg api.yourdomain.com/ v1/users/* api.yourdomain.com/v1/ users/*/history/*
  19. HTTP/S transaction metrics breakdown • App version • Device •

    Country • OS level • Carrier • Radio
  20. How HTTP/S monitoring works Bytecode manipulation (with ASM) URL url

    = new URL("https://firebase.google.com"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); URL url = new URL(“https://firebase.google.com”); HttpsURLConnection conn = (HttpsURLConnection) FirebasePerfUrlConnection.instrument(url.openConnection()); Decorator inside!
  21. How HTTP/S monitoring works dependencies { compile 'com.google.firebase:firebase-perf:11.0.2' } apply

    plugin: 'com.google.firebase.firebase-perf' Uses the Transform API