Thursday, August 28, 2014

make-android - Android bloated build system be damned!

Lately I've been working on some Android stuff.  I hadn't worked on android in awhile so I downloaded their new android studio instead of the eclipse ADT.....

Ya I know it's in beta, but are you kidding me?  A sample hello world application took like 30 seconds to build with gradle.  And gradle itself is a bloated tool.  As soon as I attempt to type

$ gradle

in terminal it makes my macbook pro sound like it's taking off into space.

So I tried going back to the ant system in ADT. There I ran into problems as the AndroidManifest.xml now lives in a different place. I tried to look and fix the 1500 line xml garbage under

$ANDROID_HOME/tools/ant/build.xml 

and quickly said WTF.

Then I said you know what I am not going to live like this.  Screw you Google, your build tools are bloated abominations I will make my own.  It turns out that building for android without all the abstractions of gradle and ant is WAY faster and to me more elegant.

The native tools 'aapt' and 'dx' helps us here.


$ANDROID_HOME/build-tools/x.x.x/aapt
$ANDROID_HOME/build-tools/x.x.x/dx


So here is a example using good old Makefile. Yes I know I could of used ant to have incremental builds, but I can do the same in make (future post) without having to spawn a new jvm instance!

https://github.com/asharif/make-android

A lot of it as you can see is to support google play services. I can't believe Googles way is to add a project in eclipse! Anyway a gradle project that took 1 minutes to build on my late 2013 Macbook Pro now takes 7 seconds. That and my laptop doesn't turn into hot coal. Also notice how I left out the part about the keys,keystore and signing. I figure that stuff is outside the scope and regular java stuff.

Enjoy!