Building Android ADB from minimal sources
01 Jul 2014At some point I wanted to have a new version of Android’s adb utility as mine was lacking the show-progress capability during adb push -p
which is very helpful for me as I often push large files over adb and by default no progress information is shown at all. However, having to download the whole 2 GB of Android sources just to be able to build adb was daunting which made me look for possibilities on how to setup a minimal build environment.
Luckily, I found Mark Seaborn’s blogpost with some instructions for an older version of the Android build environment. This helped me to setup an equivalent build environment for the current Android source version.
Setting up the Build Environment
If you are using Linux with the apt application manager installed, install the following packages first:
sudo apt-get install git build-essential libncurses5-dev
Change to a folder where all the sources should be stored
mkdir -p ~/work/adb
cd ~/work/adb
Then clone all the necessary git repositories needed to build adb from Google’s servers
git clone https://android.googlesource.com/platform/system/core.git system/core
git clone https://android.googlesource.com/platform/build.git
git clone https://android.googlesource.com/platform/external/zlib.git external/zlib
git clone https://android.googlesource.com/platform/bionic.git
git clone https://android.googlesource.com/platform/external/stlport.git external/stlport
git clone https://android.googlesource.com/platform/external/libcxx.git external/libcxx
git clone https://android.googlesource.com/platform/external/openssl.git external/openssl
Around ~79 MB need to be downloaded. Afterwards the directory structure should look like
sonntag@ubuntubox:~/work/adb$ ls
bionic build external system Makefile
sonntag@ubuntubox:~/work/adb$ du -hd1
40M ./bionic
19M ./system
40M ./build
92M ./external
189M .
Makefile Modifications
Before we can build adb, some build scripts have to be modified as was pointed out by Mark Seaborn. We have to disable the Java checks as we don’t need it to build adb. You can do it manually by editing the files
-
build/core/main.mk
Comment out all the lines$(error stop)
after a check for Java/JDK/OpenJDK. -
build/target/product/sdk.mk
Comment out all the-include external/svox/pico/lang/PicoLang*
lines at the end of the file
or you can simply use the patch file I provide here. Change to the build
directory
cd build
and download the patch via wget https://sonntam.github.io/assets/adb_build.patch
. Then you may call
git apply --stat adb_build.patch
git apply --check adb_build.patch
which will not really apply the patch but give you a brief overview of the changes the patch would apply as well as check for possible errors. Finally call
git apply adb_build.patch
to apply the patch.
Building
Now you can start the build procedure by executing
make -j4 out/host/linux-x86/bin/adb
The -j4
argument tells make to start up to 4 processes in parallel for compilation of source files. Set this number to the number of CPU cores you have on your computer. After a little while you shoud find your brand new adb executable in the out/host/linux-x86/bin
directory.