субота, 1 червня 2013 р.

State of Clojure on Android 2013

   First of all, I'd like to thank Clojure organization and Clojure community for being invited to participate in Google Summer of Code 2013. I'd like to thank Daniel Solano Gómez, the author of Android-patched Clojure fork and Neko and my last year's mentor, and Zach Oakes, my mentor for this year, the author of Nightweb. We plan to do some awesome things together this summer. But before I start, I'd like to recap the last year and analyze the current situation of Clojure on Android (CoA).

Recapping last year


   My last year's participation was successful enough to bring some attention of the community to CoA. My work resulted in creation of lein-droid - a plugin for Leiningen to seamlessly build CoA projets in Clojure-way; and fork of Neko - a convenience library that claims to bring idiomatic Clojure development practices to Android. Lein-droid managed to get 149 watchers over the year, which I suppose is a good result considering the limited target audience of the project (for comparison, Leiningen has ~2600 watchers - so roughly 5% of the community got interested in CoA).

   Over the course of the year lein-droid was polished, curated and bug-fixed to the point that now it is pretty stable (except for the moments when Google update their build toolchain, but I try to react to those quickly). It is proven to work on both *nix and Windows. Some of last year's problems that wasn't tackled, effectively became non-issues (like long dx-ing time - on my not-so modern machine it takes less than a minute which, I think, is bearable). I plan to release the final 0.1.0 version before I start working on this year's proposal to mark a clear milestone in its development.

   Neko is in a bit afloat right now. Daniel and me haven't merged our branches yet, so officially Neko still supports and prefers building with Ant and use of some concepts deprecated in my branch. I sincerely hope that we are able to finally combine our work and deliver stable version 2.0.0, again before I resume active development.

   I was incredibly excited to know that Zach Oakes developed and released Nightweb - I2P peer-to-peer anonymous social network application, written solely in Clojure using lein-droid and Neko. This is the first serious high-profile CoA application, and I'm very proud that Zach will be my mentor for this year. Giving his experience at hands-on CoA development, he knows the capabilities and limitations of the current CoA stack and can guide me through this summer's quest for better Clojure on Android experience.

Clojure on Android today


   So what can you do with CoA today and what are the current limits?

   Well, obviously you can create complete CoA applications. Lein-droid simplifies the build process to usage of a single command, without the need to touch Ant or Eclipse along the way. You can use Clojure libraries as dependencies just like you do in your JVM Clojure projects (with the only difference that the library shouldn't use JVM-specific classes that are absent on Dalvik). Besides lein-droid (when used in conjunction with neko which is by default) injects a nrepl server into your application which allows to connect to your running application on the device from the computer and develop interactively just like you are used to. Lein-droid provides a distinction between debug build and release build, and doing the latter one removes the nrepl thing automatically, so there is no overhead (although you can deliberately enable it in release builds as well). There is a brief tutorial on getting started here.

   Neko provides a bunch of useful functions and macros to simplify your CoA development. First of all, neko.ui is a namespace where the most magic happens. It allows you to define your UI declaratively and interactively in Clojure, without touching XML, and without any overhead. neko.ui takes UI specified in Clojure data structures and transforms it into Java interop calls in compile time. Right now, the number of UI widgets and properties supported by neko.ui is limited, and extending it is the first objective of my GSoC 2013 proposal. Additionally, there are utilities to work with SQLite, notifications, shared preferences, resources, logging. Neko source code is well documented, and you can also find usage documentation on project's wiki.

   Now to the said part. The main problem and limiting factor for CoA adoption remains the size of Clojure runtime. Android devices are getting more powerful everyday, but so are user expectations in terms of performance. CoA applications take some noticeable time to load (up to 10 seconds on some old devices, up to 4-5 on the latest ones); also due to high memory usage they often become candidates for the operating system to be cleaned up after they are minimized. As an example, I once wrote a simple app in Clojure that shows active processes, and a plugin for it (as a separate application, also written in Clojure); as a result, when the main app opened the plugin it was often itself closed the OS. This is certainly a repulsive experience for Android users. Fortunately though, the talks of developing a leaner Clojure runtime are out there for quite some time, and more and more people become obsessed with this idea. I think, that now when we have quite an efficient ClojureScript compiler written in Clojure, it is feasible to adapt it to compiling native Clojure code into something more lightweight.

   You still have to know Android to be able to use CoA. Actually, it was never a purpose to completely hide Java-Android behind Neko abstractions; but more than that there is a big amount of code you have to write using interop where Clojure would be more elegant. Zach has a lot to say about this. So this year' efforts are directed towards this goal too - reduce the number of interop where it makes sense to do so. Yes, you have to know Android SDK, but you don't have to care about it all the time.

   IDE support is well non-existent right now. Since CoA uses nrepl for remote interactive development, you can use Emacs/Vim/ST/Eclipse to connect to your application. Fancy stuff like jump-to-definition is currently unavailable. Moreover Android developers are quite used to IDE-driven development, especially with the goodies presented in new Android Studio. It is quite hard to win these developers over without providing them something of equal power. So yet another intent of this summer is to research if some of these IDE features can be harnessed from Clojure. The UI side is the tastiest, and since neko.ui would most probably be rewritten (I describe the reasons in my proposal), I will do it with the IDE argument in mind.

Conclusion


   Clojure on Android is definitely young, untapped and has its difficulties, but it can be exciting to explore. All you have to do is to submit to it, and I will make sure the fun is there. See you next time!

7 коментарів:

  1. Sounds good, I can't wait for the results of your work this year (:

    On a not completely unrelated note: in my spare time I'm working on code that can generate AndroidManifest.xml at compile time, freeing the developer from the burden of having to interact with it.
    Would you be interested in merging that into neko once it's more ready for general consumption?

    ВідповістиВидалити
    Відповіді
    1. Hello Joey,

      Yes, I am interested to see what you have come up with. I don't know yet if I merge it with Neko, I have to see it first. Is it some kind of Clojure data structures DSL that transforms into XML?

      Видалити
    2. In fact it is, it uses vectors for tags and maps for their attributes.

      The idea is to at compile time keep track of stuff like which permissions are used and declared, which intents are declared and used etc (basically all the stuff in http://developer.android.com/guide/topics/manifest/manifest-intro.html#filestruct), which in turn can be accomplished using macros.

      It is by no means a complete implementation yet: it just handles uses-permissions tags currently. I build it out as I go along, since I'm currently also working on an android app in Clojure.

      I can split it out into a neko fork and send you a pull request on GH if you like.

      Видалити
  2. How far did you go with the GSOC 2013 proposal. Where you still able to work on this project?

    ВідповістиВидалити
    Відповіді
    1. Hello John! The work continues, yes. You can track the progress in these projects: https://github.com/clojure-android/lein-droid and https://github.com/alexander-yakushev/neko .

      Видалити
  3. As a versatile provision designer, a few ventures interest building your own backend, while others can move quicker with an instant result. Two upgrades we are making to Google Cloud Platform help you with either situation. To help you assemble your backend, Google Cloud Endpoints has notwithstanding moved to General Availability.
    Android App Developers // Window Phone App // Mobile Application
    Development

    ВідповістиВидалити
  4. Moreover, Developers used IDE-Driven for android app development especially in android studio you can get all new applications from here can download freely and enjoyed.

    ВідповістиВидалити