BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Using Clojure to Build Native Android Apps

Using Clojure to Build Native Android Apps

This item in japanese

Clojure development on the Android platform has been progressing remarkably in the last few years, allowing developers to use it in fully fledged apps such as SwiftKey’s Clarity Keyboard. Here we will review the current status of tools that support Clojure on the Android platform.

Historically, Clojure on Android has suffered from slow startup, which could last up to 4–10 times longer than Java’s when using standard upstream Clojure. This issue is addressed by Skummet, a Clojure fork that optimizes Clojure’s compiler so that it produces more compact, faster-to-load bytecode. Besides providing an optimizing compiler, Skummet also includes an optimized version of Clojure’s runtime that is built by the former.

Skummet aims to ensure maximum compatibility and, although there could be issues with code that relies on referencing Vars directly, most Clojure code should be compatible out of the box, according to Skummet’s creator Alex Yakushev.

Overall, Skummet is able to bring a 4x reduction in load time on a simple benchmark app’s first launch, and 2x shrinking in both APK size and heap usage. According to SwiftKey’s Adam Clements and Ben Leavett, using Skummet has allowed them to keep Clarity Keyboard’s loading time around 1.5–2 seconds, and further improvements are possible.

Other useful tools for Clojure development on Android are packed under the umbrella project of Clojure-Android Initiative and include:

  • lein-droid: a Leiningen plugin that works as a build tool for Clojure-Android projects and deals with the process of packaging resources, creating an APK file, signing it, etc.
  • Neko: a toolkit that wraps some parts of Android’s Java API to make them more idiomatic to use from Clojure.

Zach Oakes, author of the Nightweb app for Android, says that Clojure can make an app’s codebase “shockingly” smaller by enabling terse idioms, as well as improve the app responsiveness by making it easier for the programmer to run asynchronous tasks.

According to SwiftKey’s engineers, the use of Clojure to build an Android app can have a huge impact on the app design. Specifically, in Clarity Keyboard’s case, it made it possible to adopt a fully “event driven” design, which coupled with the use of immutable data structure allows to easily store and “replay” any user actions. Using immutable data also helped build a highly modular app and make every operation asynchronous by default.

Rate this Article

Adoption
Style

BT