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:
- The Android NDK unpacked to a location of your choice (in my case
- The latest Dropbear and rsync source downloads in a different location to the NDK.
- The files config.guess and config.sub in the same folder as the source downloads.
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/make-standalone-toolchain.sh --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
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' make
You should now have compiled dbclient and rsync binaries ready to use under Android.