Building Android SDK build tools: aapt for Debian Arm

The Android SDK tools does not support building on Linux Arm.

I will show how to compile the build tools: aapt, aidl on a Debian Armhf (wheezy) device using the Android source.

I install Oracle 7 JDK jdk-7u51-linux-arm-vfp-hflt.tar.gz into /opt/java/jdk1.7.0_51
Though the latest version of Android in the Android Open Source Project (AOSP) requires OpenJDK 7 for Linux.

1     # update-alternatives --install /usr/bin/java java /opt/java/jdk1.7.0_51/bin/java 2000
2 # update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.7.0_51/bin/javac 2000

Refer to Installing required packages (Ubuntu) in Initializing a Build Environment for Linux.

My Debian Armhf device is My Cloud from Western Digital. You will need to enable SSH from the My Cloud dashboard. See How to enable SSH (Secure Shell) on a WD My Cloud.

The installed libc6 is a newer version (2.17-97) than the official Debian wheezy libc6 (2.13-38+deb7u1). And because the Debian libc6-dev depends on libc6 (= 2.13-38+deb7u1) , it prevents libc6-dev from being installed. I install the libc6-dev package manually by extracting the files from the deb.

Then, using the equivs tools to build an empty libc6-dev package and install it to circumvent dependency checking.

 1     # apt-get install linux-libc-dev
2 # dpkg -s libc6
3 Package: libc6
4 Status: install ok installed
5 . . .
6 Source: eglibc
7 Version: 2.17-97
8 . . .
10 # apt-get install equivs

Modify the libc6-dev package control file to change its dependency to "Depends: libc6 (>= 2.13-38+deb7u1), linux-libc-dev"

1     Package: libc6-dev
2 Source: eglibc
3 Version: 2.13-38+deb7u1
4 Architecture: armhf
5 Maintainer: GNU Libc Maintainers <[email protected]>
6 Installed-Size: 7700
7 Depends: libc6 (>= 2.13-38+deb7u1), linux-libc-dev

Install the empty libc6-dev deb that is built from equivs-build:

1     # equivs-build control
2 # dpkg -i libc6-dev_2.13-38+deb7u1_armhf.deb

Install the other required packages for the build environment:

1     # apt-get install git gnupg flex bison gperf build-essential \
2 zip curl libncurses5-dev x11proto-core-dev \
3 libx11-dev libreadline6-dev libgl1-mesa-glx libgl1-mesa-dev \
4 python-markdown libxml2-utils xsltproc zlib1g-dev

Follow the instruction on Downloading the Android Source

1     $ cd ~/android/src
2 $ repo init -u
3 $ repo sync

Repo sync will take very long time to complete the download.

To save time, you do not have to download everything. Check the instruction on Build Overview - Android Tools.

To build a full SDK, run these commands in a bash shell: (This will throw errors on Linux Arm)

1     $ cd ~/android/src
2 $ . build/
3 $ lunch sdk-eng
4 $ make sdk

The following shows the changes required. (Change/addition is highlighted/bold)
Modify build/core/ to add detection of Arm architecture.

build/core/ (@ line 76)
   ifneq (,$(findstring Power,$(UNAME)))
           HOST_ARCH := ppc
   ifneq (,$(findstring arm,$(UNAME)))
           HOST_ARCH := arm

Modify build/core/ to allow using Oracle 7 JDK

build/core/ (@ line 178)
   requires_openjdk := false
   ifeq ($(LEGACY_USE_JAVA6),)
   ifeq ($(HOST_OS), linux)
   ifneq ($(HOST_ARCH), arm)
   requires_openjdk := true

Add build/core/combo/ to define the configuration for building on host Linux Arm. Download build/core/combo/

Add build/core/clang/ for building on host Linux Arm. Download build/core/clang/

Modify build/core/combo/ (due to copying build/core/combo/include/arch/linux-arm/AndroidConfig.h to build/core/combo/include/arch/target_linux-arm/AndroidConfig.h and using the original AndroidConfig.h for host build)

build/core/combo/ (@ line 91)
   android_config_h := $(call select-android-config-h,target_linux-arm)

Modify build/core/combo/include/arch/linux-arm/AndroidConfig.h to use only for host build. Download build/core/combo/include/arch/linux-arm/AndroidConfig.h

Compiles the dependent libraries, ignoring errors for device build (it builds for both host and target/device together, seems like no option to build for host only)

   $ cd ~/android/src/external/expat
   $ mm
    . .
   $ cd ~/android/src/external/libpng
   $ mm
    . .
   $ cd ~/android/src/system/core/liblog
   $ mm
    . .
   $ cd ~/android/src/system/core/libutils
   $ mm
    . .
   $ cd ~/android/src/system/core/libcutils
   $ mm
    . .

   $ cd ~/android/src/build/libs/host
   $ mm
   $ cd ~/android/src/build/tools/acp
   $ mm

In external/zlib/, I comment off other builds except for the BUILD_HOST_STATIC_LIBRARY part and BUILD_HOST_SHARED_LIBRARY part.

   $ cd ~/android/src/external/zlib
   $ vi
   $ mm

In system/core/libziparchive/, I comment off other builds except for the BUILD_HOST_STATIC_LIBRARY part.

   $ cd ~/android/src/system/core/libziparchive
   $ vi
   $ mm

   $ cd ~/android/src/frameworks/base/libs/androidfw
   $ mm
    . .

To link bison in prebuilts, create dirs for prebuilts/misc/linux-arm/bison (used when building aidl)

   $ cd ~/android/src/prebuilts/misc/linux-arm/bison
   $ ln -s /usr/bin/bison .

After compiling aapt, the binary is found in out/host/linux-arm/bin
And compile aidl, and zipalign

   $ cd ~/android/src/frameworks/base/tools/aapt
   $ mm
    . .
   $ cd ~/android/src/frameworks/base/tools/aidl
   $ mm
    . .
   $ cd ~/android/src/build/tools/zipalign
   $ mm

I have created git repo @


blog comments powered by Disqus