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

Building Top-Notch Android SDKs - Droidcon Tunisia

Building Top-Notch Android SDKs - Droidcon Tunisia

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

March 07, 2015
Tweet

More Decks by Hugo Doménech Juárez

Other Decks in Programming

Transcript

  1. relayr bring things to life By the way, one of

    you has a chance to win a WunderBar today!! dev.relayr.io/signup
  2. • Developers are lazy - reuse code • Separate concerns

    (build independent blocs) • Write better software • Speed up compile time • Make other people happy… Reasons
  3. • 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!
  4. 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.
  5. Create a SDK! How do we start? Before writing a

    single line of code, what do we need? (public)
  6. Managing Releases Use the library in a real project SDK

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

    • Performant • Reliable • Lightweight Great SDK Qualities
  8. 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) }
  9. 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' }
  10. 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 }
  11. • Java code -> init(appId, clientId, clientSecret) • Java asset

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

    = "android.permission.VIBRATE"; int result = mContext.checkCallingOrSelfPermission(permission); return result == PackageManager.PERMISSION_GRANTED; }
  13. 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); }
  14. 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; }
  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 { } 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’
  19. 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.