Key learnings and pitfalls from building mobile SDK

Key learnings and pitfalls from building mobile SDK

Are you working on the client library? Or design a public API for the module that is going to be used by other team or department?

In this session, Vitality will share his experience and key learnings from building a set of mobile SDKs. The session will be interesting for Android and iOS developers who want to learn what makes client library great. What are the best practices and common pitfalls in public API design. What is important, only programming API you expose or also ecosystem around?

F456ed67b75e58e533d11b301f5f62b5?s=128

Vitaliy Zasadnyy

February 16, 2017
Tweet

Transcript

  1. @zasadnyy Or what did we learn in the last 4

    years Building mobile SDK Vitaliy Zasadnyy Head of Mobile @ GetSocial
  2. @zasadnyy Integrated SDK. But it doesn’t work.

  3. Developer. GDG Lead. Public Speaker. @zasadnyy

  4. None
  5. None
  6. None
  7. LISTEN

  8. SDK Lifecycle

  9. @zasadnyy SDK Lifecycle Develop 1

  10. @zasadnyy

  11. @zasadnyy SDK Lifecycle Develop 1

  12. @zasadnyy SDK Lifecycle Develop 1 Integrate 2 Support 3 Update

    4
  13. Develop 1

  14. @zasadnyy Start shaping your API Use Cases Examples Integration Tests

  15. @zasadnyy Cost of fixing issue

  16. @zasadnyy Cost of fixing issue Spend 10x more time on

    line of examples comparing to production code
  17. @zasadnyy NOT SURE? DROP IT!

  18. @zasadnyy IS BETTER LESS CODE

  19. @zasadnyy Boilerplate ➡ Copy/Paste ➡ Bugs Why?

  20. @zasadnyy GetSocial Analytics problem Almost all our clients mis-integrate analytics

    <receiver android:name="im.getsocial.InstallReferrerReceiver"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER"/> </intent-filter> </receiver>
  21. @zasadnyy How to solve? AndroidManifest merging Gradle plugin Android Studion

    plugin …
  22. @zasadnyy IS BETTER LESS CODE

  23. @zasadnyy API SURPRISES AVOID

  24. @zasadnyy Avoid API surprises Thread.interrupted() Returns the current interrupted status

    and then clears it
  25. @zasadnyy Avoid API surprises

  26. @zasadnyy Avoid API surprises Thread.interrupted() Returns the current interrupted status

    and then clears it
  27. @zasadnyy Make the API to your library as boring as

    possible - Chris Sells, Google
  28. @zasadnyy No SetListener() in C# void SetOnInviteFriendsListener ( Action onInviteFriendsIntent,

    Action<int> onFriendsInvited)
  29. @zasadnyy Much better API event Action OnInviteFriendsIntent event Action<int> OnFriendsInvited

  30. @zasadnyy Follow platform guidelines Mimic core API Avoid introducing new

    concepts
  31. @zasadnyy ? Library is crashing you app?

  32. @zasadnyy

  33. @zasadnyy CRASH HOST APP NEVER

  34. @zasadnyy GetSocial approach Rx @Nullable PMD / FindBugs / Lint

  35. @zasadnyy Rx chains Observable .just(MetaDataKey.APP_ID) .map(ValidateAppIdFunc.create()) .flatMap(TrackInstallFunc.create()) ... .subscribe((result) ->

    { ... }, (throwable) -> { // all exceptions end up here } );
  36. @zasadnyy Rx chains Observable .just(MetaDataKey.APP_ID) .map(ValidateAppIdFunc.create()) .flatMap(TrackInstallFunc.create()) ... .subscribe((result) ->

    { ... }, (throwable) -> { // all exceptions end up here } );
  37. @zasadnyy

  38. @zasadnyy INTERNALS HIDE

  39. @zasadnyy Hide internals

  40. @zasadnyy Hide internals Use .internal package Keep everything private by

    default
  41. @zasadnyy There is much more!

  42. Integrate

  43. @zasadnyy ? What is important to developers?

  44. @zasadnyy SIZE

  45. @zasadnyy List information about Library size Method count Proguard rules

  46. @zasadnyy COMPATIBILITY

  47. @zasadnyy Keep compatibility Select minimum supported platform version. After detailed

    market research Update maximum supported version. Continuously
  48. @zasadnyy SUPPORT

  49. @zasadnyy Give a voice to your users GitHub issue tracker

    Intercom Support email …
  50. @zasadnyy Get ready to repetitive questions

  51. @zasadnyy DOCS

  52. @zasadnyy Key parts Step by step tutorials Product guides API

    Reference
  53. @zasadnyy

  54. @zasadnyy

  55. @zasadnyy

  56. @zasadnyy What is wrong with snippet? CurrentUser user = getSocial.getCurrentUser();

  57. @zasadnyy What is wrong with snippet? CurrentUser user = getSocial.getCurrentUser();

  58. @zasadnyy ALL SNIPPETS MUST COMPILE

  59. @zasadnyy Better snippet import im.getsocial.sdk.GetSocial; import im.getsocial.sdk.CurrentUser; ... CurrentUser user

    = GetSocial.getInstance().getCurrentUser();
  60. @zasadnyy ? Favourite source of copy / paste code?

  61. @zasadnyy

  62. @zasadnyy DEMOS

  63. @zasadnyy Demo apps Make demos well documented Keep SDK integration

    code separated
  64. Support

  65. @zasadnyy ? You’ve got support request. Now what?

  66. @zasadnyy Two types of problems Integration time problems End-user side

    problems
  67. @zasadnyy Solving integration time problems Easy way to get SDK

    version Debug SDK configuration Unique log tag Actionable errors
  68. @zasadnyy Actionable errors public class GetSocialException extends RuntimeException { private

    final int _errorCode; … }
  69. @zasadnyy Actionable errors public class GetSocialException extends RuntimeException { private

    final int _errorCode; … }
  70. @zasadnyy Solving end-user side problems Comprehensive logs Errors analytics

  71. @zasadnyy Solving end-user side problems private void trackError(GetSocialException exception) {

    ... AnalyticsTrackManager.trackAnalyticsEvent( AnalyticsEventDetails.Name.SDK_ERROR, eventProperties); }
  72. @zasadnyy s THINK ABOUT SUPPORT AHEAD

  73. Update

  74. @zasadnyy ? Why developers update SDKs?

  75. @zasadnyy Update. Build. And…

  76. @zasadnyy

  77. @zasadnyy UPDATES SMOOTH

  78. @zasadnyy Backward compatibility Use @Deprecation cycle /** * @deprecated use

    {@link #getAllIdentities()} instead. * Method will be removed in SDK v5.0.0. */ @Deprecated public List<String> getIdentities() { ... }
  79. @zasadnyy Semantic versioning v4.5.1 Major Minor Bugfix

  80. @zasadnyy Versioned packages import okhttp3; import im.getsocial.sdk6;

  81. @zasadnyy Versioned packages import okhttp3; import im.getsocial.sdk6; Partial transition A/B

    testing
  82. @zasadnyy Changelog Fixed issues Added features Compatibility changes API changes

  83. @zasadnyy

  84. To sum up

  85. @zasadnyy SDK Lifecycle Develop 1

  86. @zasadnyy SDK Lifecycle Develop Integrate Support Update 1 2 3

    4
  87. @zasadnyy Develop 1 Integrate 2 Support 3 Update 4 Not

    sure? Drop it! Never crash Be your own customer Think ahead Smooth
  88. @zasadnyy API can be you biggest asset of liability -

    Joshua Bloch Put yourself in your customer’s shoes - Cesare Rocchi
  89. @zasadnyy Happy dog Make developers happy again.

  90. @zasadnyy @zasadnyy / zasadnyy.com Questions? Mulțumesc!