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

Building Top-Notch SDKs - Droidcon Krakow

Building Top-Notch SDKs - Droidcon Krakow

The Android app ecosystem is growing and it's time to make it easier for developers to build better apps. There is a need for better tools and libraries to make everyday's work more efficient. This talk aims to create a minimum viable SDK. A set of best practices, tips and tricks learnt whilst building the relayr SDK [dev.relayr.io] for accessing real world sensor data from the WunderBar, in a step-by-step approach to show you how it should look like and let you focus on the functionality you want to provide.

Hugo Doménech Juárez

December 03, 2014
Tweet

More Decks by Hugo Doménech Juárez

Other Decks in Programming

Transcript

  1. • Developers are lazy - reuse code • Separate concerns

    (build independent blocs) • Write better software • Speed up compile time • Make other people happy… Reasons
  2. • Feel better • Code better: Power of shame •

    Get features and bug fixes for free • Easier to sell - quality prove • Excitement from the community • Security • It’s free • But most important: Be famous! Make it open source!
  3. 1. Don’t start with code: README.md and ROADMAP.md 2. Put

    it in a Git Repository 3. Include it in your CI (Continuous Integration) 4. Add static code analysis tools (i.e. FindBugs, Lint) 5. Autogenerate documentation (i.e. JavaDoc) 6. Prepare for testing 7. Make it accessible (i.e. distribute via maven) 8. Add a sample project Create a SDK!
  4. Managing Releases Use the library in a real project SDK

    as a git submodule Master Master Develop Develop Feature Branch Feature Branch
  5. • Available • Easy to use • Flexible • Testable

    • Performant • Reliable • Lightweight Great SDK Qualities
  6. • Easy to initialise • Easy to use Easy to

    use RelayrSdk.init(this); RelayrSdk.logMessage(“At droidcon Krakow!”);
  7. Flexible - minimize permisions public boolean canVibrate() { String permission

    = "android.permission.VIBRATE"; int result = mContext.checkCallingOrSelfPermission(permission); return result == PackageManager.PERMISSION_GRANTED; }
  8. Flexible - minimize requisites <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-feature android:name=“android.hardware.bluetooth_le"

    android:required="false"/> public boolean isBleSupported() { String feature = PackageManager.FEATURE_BLUETOOTH_LE; return getPackageManager().hasSystemFeature(feature); }
  9. Flexible - support different versions defaultConfig { applicationId 'io.relayr.wunderbar' minSdkVersion

    15 targetSdkVersion 21 versionCode 22 versionName '1.0.22' } public boolean isSdk18() { return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; }
  10. • Mock mode (no network requests) • No static methods

    • Avoid final classes • Avoid access to fields directly Testable
  11. • With Code Performant - Don’t log in production RelayrSdk.Builder(this)

    .setDebuggable(false) .build(); debuggable=false • On the Manifest
  12. • Don’t crash silently - inform the user when a

    problem occurs Reliable RelayrSdk.login(new LoginCallback() { public void onSuccess() { // sign the user into the app } public void onError() { // show error message } });
  13. • Poor network conditions • Association between small and fast

    • Reluctance to include large libraries Lightweight
  14. Lightweight - don’t require libraries private boolean hasOkHttpOnClasspath() { try

    { Class.forName("com.squareup.okhttp.OkHttpClient"); return true; } catch (ClassNotFoundException e) { } return false; } dependencies { provided ‘com.squareup.okhttp:okhttp:2.0.0’ }
  15. Lightweight - be modular dependencies { } include ‘io.relayr:java-sdk:0.0.5’ include

    ‘io.relayr:android-sdk:0.0.5’ include ‘io.relayr:android-onboarding:0.0.7’ include ‘io.relayr:master-module:1.2.0’ include ‘io.relayr:android-commons:1.0.0’