How to compile iperf3 for Android
This is a straightforward guide on how to compile iperf3 for Android
After struggling for a couple of hours trying to build an executable for Android using a stable version of iperf3 source code I finally came to a happy ending.
This article is more like a guide on how to achieve that than anything else, so if you're having any problems doing so I hope this can help you.
First things first
In order to get iperf3 compiled for Android you'll need:
- iperf3 source code — You can find it here: https://github.com/esnet/iperf
- Android NDK — Download it here: https://developer.android.com/ndk/downloads
Compiling for Android? We're gonna need an Android Toolchain! That's why we have just downloaded the Android NDK. So let's make a toolchain available.
Go to your Android NDK location and access the folder build/tools
Once there, run the command:
./make-standalone-toolchain.sh — toolchain=arm-linux-androideabi-4.9 — arch=arm — install-dir=YOUR_OUTPUT_DIR — platform=android-24 — force
- — toolchain: the name of the toolchain you're making. Android NDK comes with some toolchains. To check which ones are available go to the folder toolchains under your Android NDK location
- — arch: name of the processor architecture you're building to, in this case we're using arm as the majority of Android devices run on this architecture
- — install-dir: this is the directory where the toolchain will be installed
- — platform: as in Android projects, this is the Android API version you're building to
- — force: this parameter ensure that you're doing a fresh install. If there's any file in the install-dir related to the toolchain, it'll be erased and new ones will be created
Once you have the toolchain installed it's time to pay iperf3 some attention.
Go to your iperf3 source code location and there will be a configure file. This file is the entry point of all configuration you might need to do to compile iperf3 in a no default way.
Run the following:
./configure -host=arm-none-eabi CXX=PATH_TO_ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-g++ CXXFLAGS=-static CC=PATH_TO_ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-gcc CFLAGS=-static -C AR=PATH_TO_ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-ar RANLIB=PATH_TO_ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-ranlib — prefix=YOUR_IPERF3_INSTALL_DIRECTORY
- — host: system we're compiling to. In this case we're using arm-none-eabi that abstracts processor vendors and customisation, so it "should run" on any arm based device
- CXX: C++ compiler
- CXXFLAGS: flags for C++ compiler
- CC: C compiler
- CFLAGS: flags for C compiler
- AR: archiver
- RANLIB: indexer
- — prefix: directory where iperf3 will be installed
Final step is to make it:
make; make install;
When finished, iperf3 will be available at — prefix specified location. The executable is found under the bin folder.
This is it
That's all! After finishing building you can use the iperf3 executable in your Android devices via adb or in your application.