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

Building Top-Notch Android SDKs - Droidcon Italy

Building Top-Notch Android SDKs - Droidcon Italy

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

April 10, 2015
Tweet

More Decks by Hugo Doménech Juárez

Other Decks in Programming

Transcript

  1. • Ease to use of the platform • Oauth, Http

    client, parsing, ble services… • Separate concerns • Branding Reasons
  2. • Feel better - Sharing is caring • Code better

    - Power of shame • Easier to sell - quality prove • Get features and bug fixes for free • Security • It’s free • But most important… Be transparent: open source it!
  3. 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.
  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. 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) }
  7. 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' }
  8. 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 }
  9. • Java code -> init(appId, clientId, clientSecret) • Java asset

    -> .properties • Android Manifest -> meta-data Easy to use - Initialisation
  10. Flexible - minimize permisions public boolean canAccessBluetooth() { String permission

    = "android.permission.BLUETOOTH"; int result = mContext.checkCallingOrSelfPermission(permission); return result == PackageManager.PERMISSION_GRANTED; }
  11. 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); }
  12. Flexible - support different versions defaultConfig { applicationId 'io.relayr.wunderbar' minSdkVersion

    15 targetSdkVersion 21 versionCode 22 versionName '1.0.36' } public boolean isSdk18() { return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; }
  13. Performant interface UserApi { List<Device> getDevices(); } interface UserApi {

    void getDevices(Callback callback); } interface UserApi { Observable<List<Device>> getDevices(); }
  14. Performant List<Device> devices = user.getDevices(); user.getDevices(new Callback() { public void

    onSuccess(List<Device> devices) { } public void onError(Error error) { } }); user.getDevices() .subscribe( (List<Device> devices) -> { } )
  15. • With Code Performant - Don’t log in production RelayrSdk.Builder(this)

    .setDebuggable(false) .build(); debuggable=false • On the Manifest
  16. • 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 } });
  17. 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’ }
  18. Lightweight - be modular dependencies { } compile ‘io.relayr:java-sdk:0.0.5’ compile

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