Slide 1

Slide 1 text

Building Top-Notch Android SDKs Hugo Doménech @hudomju

Slide 2

Slide 2 text

relayr bring things to life

Slide 3

Slide 3 text

relayr bring things to life easy tools to connect things and apps

Slide 4

Slide 4 text

Building Top-Notch Android SDKs Hugo Doménech @hudomju

Slide 5

Slide 5 text

Agenda 1. Why? 2. How? 3. What?

Slide 6

Slide 6 text

Agenda 1. Why? 2. How? 3. What?

Slide 7

Slide 7 text

• Developers are lazy - reuse code • Separate concerns (build independent blocs) • Write better software • Speed up compile time • Make other people happy… Reasons

Slide 8

Slide 8 text

• 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!

Slide 9

Slide 9 text

Agenda 1. Why? 2. How? 3. What?

Slide 10

Slide 10 text

Decide what you are providing Library Project jar (Java ARchive) Apk Lib aar (Android Archive Resource)

Slide 11

Slide 11 text

Let’s build a SDK!

Slide 12

Slide 12 text

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!

Slide 13

Slide 13 text

Managing Releases Use the library in a real project SDK as a git submodule Master Master Develop Develop Feature Branch Feature Branch

Slide 14

Slide 14 text

Agenda 1. Why? 2. How? 3. What?

Slide 15

Slide 15 text

• Available • Easy to use • Flexible • Testable • Performant • Reliable • Lightweight Great SDK Qualities

Slide 16

Slide 16 text

Available dependencies { include ‘io.relayr:android-sdk:0.0.5’ } build.gradle *gradle-mvn-push.gradle by Chris Banes

Slide 17

Slide 17 text

• Intuitive • Consistent • Easy to use, hard to misuse Easy to use

Slide 18

Slide 18 text

• Easy to initialise • Easy to use Easy to use RelayrSdk.init(this); RelayrSdk.logMessage(“At droidcon Krakow!”);

Slide 19

Slide 19 text

Flexible new RelayrSdk.Builder(this) .inMockMode(true) .apiEndpoint(“api.relayr.io”) .withDebugger(new DefaultDebugger()) .build();

Slide 20

Slide 20 text

Flexible - minimize permisions

Slide 21

Slide 21 text

Flexible - minimize permisions public boolean canVibrate() { String permission = "android.permission.VIBRATE"; int result = mContext.checkCallingOrSelfPermission(permission); return result == PackageManager.PERMISSION_GRANTED; }

Slide 22

Slide 22 text

Flexible - minimize requisites public boolean isBleSupported() { String feature = PackageManager.FEATURE_BLUETOOTH_LE; return getPackageManager().hasSystemFeature(feature); }

Slide 23

Slide 23 text

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; }

Slide 24

Slide 24 text

mApplication.registerActivityLifecycleCallbacks( new Application.ActivityLifecycleCallbacks() { @Override public void onActivityResumed(Activity activity) { // we know there’s a UI! } } ); Flexible - be context aware

Slide 25

Slide 25 text

• Mock mode (no network requests) • No static methods • Avoid final classes • Avoid access to fields directly Testable

Slide 26

Slide 26 text

• Don’t block the current thread! Performant RelayrSdk.sendMessage(“At droidcon Krakow!”);

Slide 27

Slide 27 text

• With Code Performant - Don’t log in production RelayrSdk.Builder(this) .setDebuggable(false) .build(); debuggable=false • On the Manifest

Slide 28

Slide 28 text

• 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 } });

Slide 29

Slide 29 text

• Poor network conditions • Association between small and fast • Reluctance to include large libraries Lightweight

Slide 30

Slide 30 text

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’ }

Slide 31

Slide 31 text

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’

Slide 32

Slide 32 text

Recapitulate 1. Why? 2. How? 3. What?

Slide 33

Slide 33 text

Take away

Slide 34

Slide 34 text

Questions? Hugo Doménech @hudomju

Slide 35

Slide 35 text

No content