Build DMD for Android

From D Wiki
Revision as of 12:20, 17 August 2014 by Joakim (talk | contribs) (How to build druntime and phobos for Android/x86)
Jump to: navigation, search

This is a work in progress: Android/x86 is mostly done, going to work on Android/ARM next. Almost all the druntime/phobos unit tests pass on Android/x86 and a sample C/OpenGLES 1.0 purely native app from the NDK has been ported to D.


  • 32-bit linux/x86 host on which to build dmd
    • A virtual machine like VirtualBox/VMware will work fine, but you should have at least 512 MB of memory allocated and 1 GB of swap, particularly if building the phobos unit tests, and 10 GB of disk space.
  • C++ compiler and toolchain, to build dmd
  • dmd/druntime/phobos source
    • Get druntime and phobos from git, as they have Android-specific changes that are not in the release branches yet.
  • Android native toolchain, the 32-bit NDK and SDK
    • The "SDK Tools only" version of the SDK is enough, if you don't plan on using their IDE integration. I will only write about using the command-line tools.
  • Android/x86, whether a device or VM

To install Android/x86 in a VM

Download the Android-x86 iso and install as normal: it'll put you through a configuration process, but you can skip every step. Go to Settings->Security and disable the Verify Apps option, or it'll ask you about that every time you install a test app. Alt-F1 will take you to a root shell, which you'll want to do any time you're not using Android/x86 for a couple minutes or the screen will eventually go black and the VM will freeze up. Alt-F7 takes you back to the normal GUI screen.

Build D for Android/x86

Download the patch for DMD, apply it, and build normally:

cd dmd
git apply packed_tls_for_elf.patch
make -f posix.mak -j5

This patch adds TLS support for Android/x86 to DMD, more info can be found on the pull request for DMD.

Assuming druntime and phobos are in the same directory as dmd, download and apply the patch for druntime and the one for phobos, set the NDK environment variable to the path of wherever you installed the NDK, and build each in turn:

cd ../druntime
export NDK=/path/to/your/android-ndk-r10
git apply druntime_build.patch
make -f posix.mak PIC=1

cd ../phobos
git apply phobos_build.patch
make -f posix.mak PIC=1

Both patches avoid building druntime/phobos as a shared library and set the appropriate C compiler and flags. The druntime patch also adds an import I missed before.

More to come on how I extracted those C compiler/flags NDK commands and how to build a sample app.