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

Building the Fabric SDKs - #MBLTDev (30 min)

7a3baf2e1158e358885cdf7e89b9aa55?s=47 Ty Smith
October 28, 2014

Building the Fabric SDKs - #MBLTDev (30 min)

7a3baf2e1158e358885cdf7e89b9aa55?s=128

Ty Smith

October 28, 2014
Tweet

Transcript

  1. dev.twitter.com @tsmith Building the Fabric SDKs Ty Smith Sr. Android

    Engineer
  2. None
  3. None
  4. None
  5. None
  6. Fabric Sample App Cannonball Open source for iOS & Android:

    github.com/twitterdev
  7. Powerful Lightweight

  8. Powerful

  9. Ease of Integration

  10. Ease of Integration Fabric.with(this, new Crashlytics());

  11. Extensible

  12. Extensible Crashlytics.start(this);

  13. Extensible Crashlytics.start(this, 5); Crashlytics.setListener(createCrashlyticsListener()); Crashlytics.setPinningInfo(createPinningInfoProvider()) Crashlytics.getInstance().setDebugMode(true);

  14. Extensible Crashlytics.setListener(createCrashlyticsListener()); Crashlytics.setPinningInfo(createPinningInfoProvider()); Crashlytics.getInstance().setDebugMode(true); Crashlytics.start(this, 5);

  15. Extensible Crashlytics.start(this, delay, listener, pinningInfo, debugMode);

  16. Extensible Crashlytics.start(this, 0, null, null, null, true);

  17. Fluent Pattern Crashlytics crashlytics = new Crashlytics.Builder() .delay(1) .listener(createCrashlyticsListener()) .pinningInfo(createPinningInfoProvider())

    .build(); Fabric.with(this, crashlytics);
  18. Fluent Pattern Fabric.with(new Fabric.Builder(this) .kits(new Crashlytics()) .debuggable(true) .logger(new DefaultLogger(Log.VERBOSE)) .looper(getCustomLooper())

    .executor(getCustomExecutorService()) .build());
  19. Extensible Classes class MyApiClient extends TwitterApiClient { interface MyService {

    @GET(“/1.1/statuses/show.json”) Tweet getTweet(@Query(“id”) int id); } MyService getMyService() { return getService(MyService.class); } }
  20. Gracefully Degrade

  21. Gracefully Degrade if (TextUtils.isEmpty(apiKey) if (debuggable){ throw new IllegalArgumentException( “apiKey

    is null!"); } else { return null; } }
  22. Minimizing Permissions

  23. Minimizing Permissions <uses-permission android:name="android.permission.INTERNET"/>

  24. Minimizing Permissions Crashlytics.setUserEmail(“appuser@domain.com”);

  25. Permissions: Runtime Detection protected boolean canCheckNetworkState() { String permission =

    Manifest.permission.ACCESS_NETWORK_STATE; int result = context.checkCallingOrSelfPermission(permission); return (result == PackageManager.PERMISSION_GRANTED); }
  26. Multiple Application Types

  27. Multiple Application Types package com.example; import android.app.Service; public class MyService

    extends Service { }
  28. UI from Application Context WeakReference<Activity> currentActivity = new WeakReference<Activity>(); @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)

    void registerLifecycleCallbacks() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { final Application app = ((Application)context); app.registerActivityLifecycleCallbacks( new ActivityLifecycleCallbacks() { @Override public void onActivityResumed(Activity activity) { currentActivity.set(activity); } }); } }
  29. Powerful SDKs Ease of Integration Extensibility Support all app types

    Permission detection
  30. Lightweight

  31. Binary Size

  32. Binary Size

  33. 3rd Party Library Mindfulness

  34. 3rd Party Library Mindfulness

  35. How big are Fabric AARs? Fabric: 190kb Crashlytics: 90kb Beta:

    13kb Answers: 20kb Twitter API & SSO: 296kb Tweet UI: 120kb Tweet Composer: 5kb Digits: 236kb
  36. 3rd Party Library Mindfulness PROTOBUF KB OURS KB

  37. Dalvik Method Count

  38. Dalvik Method Count >./gradlew assemble … Unable to execute dex:

    method ID not in [0, 0xffff]: 65536 Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
  39. Dalvik Method Count > git clone git@github.com:mihaip/dex-method-counts.git > cd dex-method-counts

    > ant jar > ./dex-method-counts path/to/App.apk Read in 65490 method IDs. <root>: 65490 : 3 accessibilityservice: 6 bluetooth: 2 content: 248 pm: 22 res: 45 ... com: 53881 adjust: 283 sdk: 283
  40. Minimize Network Usage

  41. Network Usage 10X SMALLER 100X FASTER XML PROTOBUF

  42. Reduce Startup Time

  43. Startup Time Thread.start(); Executors.newSingleThreadExecutor();

  44. Startup Time class MyThreadFactory implements ThreadFactory { @Override public Thread

    newThread(Runnable runnable) { final Thread thread = new Thread(runnable); thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND); return thread; } }
  45. Lightweight SDKs Binary size 3rd party library mindfulness Dalvik Method

    Count Network usage Startup time
  46. Lightweight Powerful

  47. Questions? dev.twitter.com @tsmith