Cross-compiling Dropbear and rsync for Android

Update: 05 March 2020

I’ve published updated Android build scripts and configuration on GitHub for both Dropbear and rsync. These run automatically under GitHub Actions with the built binaries available to download as releases.

For convenience, you can also use the following links to download the current latest releases:

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.

Environment

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/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.

Dropbear

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

Rsync

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.

References

Comments

comments powered by Disqus