Cross-compiling Dropbear and rsync for Android

27 January 2015

I use rsync to sync my music to and back up the files from my Nexus 4. However, with the release of Android 5, my Android binaries of rsync and dropbear (which I'm using as an SSH client for rsync) refused to run with the message error: only position independent executables (PIE) are supported. This is because Android 5 only allows binaries compiled using the -pie switch to make them position independent.

As I couldn't find any pre-compiled PIE rsync and Dropbear binaries on the web I built them myself and thought it would be useful to document the process for others. I compiled the binaries under Cygwin on 64-bit Windows, but the process should be pretty similar if you are using Linux.


Firstly, you need:

Next, to set up the correct environment for compilation, open a bash shell where the source downloads are located and run the following commands:

NDK=$(cygpath 'F:\android-ndk-r10c')
$NDK/build/tools/ --platform=android-21 --install-dir=toolchain --system=windows-x86_64
export PATH=$PWD/toolchain/bin:$PATH

You should now be all set to start compiling.


First, extract Dropbear:

tar -jxvf dropbear-*.tar.bz2
cd dropbear-*

Next, the file cli-auth.c needs to be tweaked slightly to make it compile. Simply comment out the line password = getpass(prompt); This was at line 342 in the version I downloaded. Once you have done that, you are ready to run the configure script and compile:

cp ../config.guess ../config.sub .
./configure --build=x86_64-windows --host=arm-linux-androideabi \
  --disable-zlib --disable-largefile --disable-loginfunc \
  --disable-shadow --disable-utmp --disable-utmpx --disable-wtmp \
  --disable-wtmpx --disable-pututline --disable-pututxline --disable-lastlog \
  CFLAGS='-Os -W -Wall -fPIE' LDFLAGS='-fPIE -pie'
make dbclient


Building rsync is rather easier:

cd ..
tar -zxvf rsync-*.tar.gz
cd rsync-*
./configure --build=x86_64-windows --host=arm-linux-androideabi \
  CFLAGS='-Os -W -Wall -fPIE' LDFLAGS='-fPIE -pie'

You should now have compiled dbclient and rsync binaries ready to use under Android.



comments powered by Disqus