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

No content

Slide 5

Slide 5 text

relayr bring things to life By the way, one of you has a chance to win a WunderBar today!! dev.relayr.io/signup

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 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… Make it open source!

Slide 12

Slide 12 text

Be Famous!

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Decide what you are providing Library Project jar (Java ARchive) Apk Lib aar (Android Archive Resource) Library project, oldest standard android library project, standard checkout source code, you can link your source to, you can make reviews and edit it, but it’s not easy upgradable, there is no versioning. So it’s not the most flexible. JARs: great if you want to create a java library but they don’t include views or anything coming from android so if you don’t need it, it’s fine but as soon as you try to use some android related functionality it won’t work. ApkLibs: community focused effort around delivering library projects over a maven repository. It’s basically a compressed version of an android library project where the android maven plugin includes the library project in the generated source code folder. But it’s not the recommended way and it doesn’t play well with some tools. aar: recommended way by google, integrates seemlessly into gradle, supported by maven, it supports views. It’s a zip that compiles code and resources.

Slide 15

Slide 15 text

Let’s build a SDK!

Slide 16

Slide 16 text

Create a SDK! How do we start? Before writing a single line of code, what do we need? (public)

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

relayr bring things to life apply plugin: 'maven' apply plugin: ‘signing’ afterEvaluate { project -> uploadArchives { repositories { mavenDeployer { beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } pom.groupId = ‘io.relayr’ pom.artifactId = ‘android-sdk’ pom.version = android.defaultConfig.versionName repository(url: mUrl) { authentication(userName: mUser, password: mPassword) }

Slide 22

Slide 22 text

relayr bring things to life pom.project { name ‘Relayr Android SDK’ packaging ‘aar’ description ‘SDK for connecting to the Relayr Cloud’ url ‘https://github.com/relayr/android-sdk/' licenses { license { name 'The MIT License' url 'http://ithings4u.mit-license.org/' distribution ‘repo' } } developers { developer { id 'hugodomenechjuarez' name 'Hugo Doménech Juárez' }

Slide 23

Slide 23 text

relayr bring things to life signing { required { isReleaseBuild() && gradle.taskGraph.hasTask(‘uploadArchives’) } sign configurations.archives } task androidJavadocsJar(type: Jar, dependsOn: bundleJavadocRelease) { classifier = 'javadoc' from bundleJavadocRelease.destinationDir } task androidSourcesJar(type: Jar) { classifier = 'sources' from android.sourceSets.main.java.sourceFiles } artifacts { archives androidSourcesJar archives androidJavadocsJar }

Slide 24

Slide 24 text

• Java code -> init(appId, clientId, clientSecret) • Java asset -> .properties • Android Manifest -> meta-data Easy to use - Initialisation

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

• RelayrSdk sdk = new RelayrSdk(context); • sdk.logMessage(“Hola!”); • Any problems? Easy to use

Slide 27

Slide 27 text

• RelayrSdk.init(context); • RelayrSdk.logMessage(“Hola!”); • Any problems? Easy to use

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Flexible - minimize permisions

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 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 33

Slide 33 text

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

Slide 34

Slide 34 text

• Mock mode (no network requests) • No static methods • Avoid final classes Testable

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

• Don’t crash silently - inform the user when a problem occurs Reliable RelayrSdk.login(new LoginCallback() { public void onSuccess(User user) { // sign the user into the app } public void onError(Error error) { // show error message } });

Slide 38

Slide 38 text

• Poor network conditions • Reluctance to include large libraries Lightweight

Slide 39

Slide 39 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 40

Slide 40 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 41

Slide 41 text

Take away Everyone should be building their code thinking about libraries. There are always parts of your applications that could be separated into different projects, generalised and published for other people to benefit from. You will end up writing better code and being happier.

Slide 42

Slide 42 text

Questions? Hugo Doménech @hudomju

Slide 43

Slide 43 text

No content