Building Top-Notch Androids SDKs

Post on 14-Jul-2015

166 views 2 download

Tags:

Transcript of Building Top-Notch Androids SDKs

Building Top-Notch Android SDKs

Hugo Doménech @hudomju

relayrbring things to life

relayrbring things to life

easy tools to connectthings and apps

Building Top-Notch Android SDKs

Hugo Doménech @hudomju

Agenda

1. Why?

2. How?

3. What?

Agenda

1. Why?

2. How?

3. What?

• Developers are lazy - reuse code

• Separate concerns (build independent blocs)

• Write better software

• Speed up compile time

• Make other people happy…

Reasons

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

Agenda

1. Why?

2. How?

3. What?

Decide what you are providing

Library Project jar (Java ARchive)

Apk Lib aar (Android Archive Resource)

Let’s build a SDK!

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!

Managing Releases

Use the library in a real project

SDK as a git submodule

Master

Master

Develop

Develop

Feature Branch

Feature Branch

Agenda

1. Why?

2. How?

3. What?

• Available

• Easy to use

• Flexible

• Testable

• Performant

• Reliable

• Lightweight

Great SDK Qualities

Available

dependencies { include ‘io.relayr:android-sdk:0.0.5’}

build.gradle

*gradle-mvn-push.gradle by Chris Banes

• Intuitive

• Consistent

• Easy to use, hard to misuse

Easy to use

• Easy to initialise

• Easy to use

Easy to use

RelayrSdk.init(this);

RelayrSdk.logMessage(“At droidcon Krakow!”);

Flexible

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

Flexible - minimize permisions

Flexible - minimize permisions

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

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

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

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

Flexible - be context aware

• Mock mode (no network requests)

• No static methods

• Avoid final classes

• Avoid access to fields directly

Testable

• Don’t block the current thread!

Performant

RelayrSdk.sendMessage(“At droidcon Krakow!”);

• With Code

Performant - Don’t log in production

RelayrSdk.Builder(this) .setDebuggable(false) .build();

debuggable=false

• On the Manifest

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

• Poor network conditions

• Association between small and fast

• Reluctance to include large libraries

Lightweight

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

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’

Recapitulate

1. Why?

2. How?

3. What?

Take away

Questions?Hugo Doménech

@hudomju