Android NDK & Gradle

One small step toward a sane Android build environment.

I re-formatted my machine to kick off the new year and it's great. The clean slate makes you re-consider all sorts of decisions about your computing behavior and organization. One of my newest decisions is that I want to avoid installing Eclipse. I “admire” the flexibility of the platform which, through a rat’s nest of plugins, can accomplish more or less anything. It gives me a feeling of nostalgia for my high school Java class and its instructor, to whom I owe a ton. However as a former co-worker told me on my last day at the job “You’ve got to flush the toilet”.

The latest release of the Android Gradle plugin (0.7.3) seems to have quietly added support for the NDK: the one hold-out feature that prevents me from unequivocally recommending the switch from ANT, ADT and, of course, Eclipse. The NDK is the bridge to a universe of FOSS libraries and enables cross platform development.

So anyway, go check out the only real reference to Android’s Gradle NDK support in a buried link to the Android gradle samples. Look for the ndkSanAngeles sample. It looks like the new build system will replace the need to write Android Makefiles with some pretty groovy additions to your build.gradle. For example, to build a single example.c file in your project’s jni/ directory:

defaultConfig {
        ndk {
            moduleName "example"
            cFlags "-march=armv7-a -mfloat-abi=softfp -mfpu=neon"
            ldLibs "llog", "lz"

Effectively replaces the following Android Makefile:
LOCAL_PATH := $(call my-dir)

APP_PLATFORM := android-XX
include $(CLEAR_VARS)

LOCAL_LDLIBS += -llog -lz
LOCAL_SRC_FILES := example.c
LOCAL_CFLAGS := -march=armv7-a -mfloat-abi=softfp -mfpu=neon
LOCAL_MODULE := example


I like the direction Xavier Durochet and the Android tools gang are going. Hope they keep it up.

Now a dream: Can we rethink [bionic]( to include full glibc support and make native development really feel first-class?

04 Jan 2014