Compile Android on Linux

In the following we describe how the EPT source code can be compiled for an Android device on a Linux computer. It is assumed that you have already cloned the source code from our repository at gitlab. Please carry out the following steps:

1. Configure and connect your Android device

Enable debug mode on your tablet /smartphone.

  • On Android 3.2 or older, you can find the option under Settings > Applications > Development.
  • On Android 4.0 and newer, it's in Settings > Developer options.
  • On Android 4.2 and newer, developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.

Determine the vendor ID of your device. They are listed e.g. in USB Vendor IDs.

On your Linux developing system, log in as root and open the file named:

/etc/udev/rules.d/51-android.rules

Add the following line to this file (replacing 04e8 by your vendor id):

SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="plugdev"

Set the correct rights by typing:

chmod a+r /etc/udev/rules.d/51-android.rules

Now connect your smartphone/tablet to the desktop via USB and type

adb devices

You should see an entry below "List of Devices", e.g. like

List of devices attached
0123456789ABCDEF        device

2. Install Qt

If not yet done, download the open source version of Qt from the Qt website.

Download the installer, make it executable, start it, and follow the instructions.

Install Qt locally in a directory of your choice, e.g. ~/Qt

3. Install Android SDK

Go to the local directory where you want to install the Android Development Kit (SDK). Download the Linux SDK installer and save the file to this directory (the same file for 32 and 64 bit). By unpacking the tgz file you should get a folder named android-sdk-linux in the installation directory.

Start the updater by typing android-sdk-linux/tools/android update sdk --no-ui and confirm the copyrights two times. The update takes about 20 minutes. Meanwhile you may proceed with the next steps.

After completion rerun android-sdk-linux/tools/android  in order to see whether there are other updates available.

4. Install Android NDK

Android is primarily Java-based. In order to make it C++-compatible for the EPT, we need to download the NDK. Download the 32-bit or 64-bit Linux version of NDK and save the file to the installation directory of your choice. Make the downloaded bin file executable and start it:

chmod +x android-ndk-r10e-linux-x86_64.bin; ./android-ndk-r10e-linux-x86_64.bin

After some time the installation process should terminate with the message "Everything is OK".

5. Donwload dependencies

Download the dependencies (platform-specific pre-compiled components) from our download website, save it in the main directory called Etnropy-Piano-Tuner/ and unpack it. As a result you should obtain a folder Entropy-Piano-Runer/dependencies/

6. Download and compile FFTW3 for Android

Download the tar.gz installation file from the FFTW3 website, save it in the installation directory and unpack it. You should get a directory named fftw-3.3.4.

Then copy the file Entropy-Piano-Tuner/scripts/dependencies/android_configure.sh to the fftw directory. Open this file (now at fftw-3.3.4/android-configure.sh) in a text editor of your choice. Then edit the first entries according to the architecture of your system. For example, compiling the code for a tablet with ARM processor on a linux system we would have to set

ANDROID_NDK_PATH=/home/hinrichsen/Software/android-ndk-r10e
PLATFORM=linux-x86_64
PLATFORM_VERSION=21
ARCHITECTURE=arm
TOOLCHAIN_VERSION=4.9

Then type the command (with two dots in the beginning which are correct and important):

. ./android_configure.sh

Then the FFTW3 package will be compiled which takes about a minute. Having completed the script type

make -j
make install

7. Install 32 bit versions of zlib and libstdc++

These packages can be found in the distribution (e.g. zlib-devel-32bit and libstdc++6-32bit).

8. Install Java JDK

For Android compilation the Java Development Kit (JDK) is needed. On many systems one finds only the Java Runtime Environment (JRE) which is a subset of JDK. To install JDK, one has to install certain packages (e.g. java-devel on OpenSuse). Make sure that JDK is properly installed on your system. Later we will need the path to the Java compiler (javac). The path can be determined by typing

update-alternatives --config javac

which gives an output like

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac   1805      auto mode
  1            /usr/lib64/jvm/java-1.7.0-openjdk/bin/javac   1705      manual mode
  2            /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac   1805      manual mode

9. Add JDK / SDK / NDK paths to QtCreator

Open the entropytuner project in the Qt-Creator, choose the menu entry 'Tools->Options' and select 'Android' in the left toolbar of the dialog. Add the JDK path (e.g. /usr/lib64/jvm/java-1.8.0-openjdk) as well as the paths for SDK and NDK (android-sdk-linux and android-ndk-r10e).

Check the two tickmark boxes for automatic toolchain generation and for replacing Ant by Gradle. The Ant-file does not need to be specified.

Click OK to close the dialog

10. Install a virtual device

Although it is not necessary, it is useful to install an Android Virtual Device (AVD), which is an emulator of a tablet or a smartphone on the desktop. However, rigorous testing should always be done on a real device.

To install a virtual device run  android-sdk-linux/tools/android  A window opens which shows the installed SDK components. Choose 'Tools->Manage AVD's' and select 'Create'. Choose an AVD Name (e.g. 'MyVirtualTablet') and specify the properties of the device (we are using 10.1" WXGA (Tablet), Android 6.0, ARM (armeabi-v7a), No Hardware keyboard present, Skin WXGA800, no cameras

11. Add a build target for Android

Choose 'Projects' in the left toolbar of the main window. Click on 'Add kit' and select the Android entry, e.g. 'armeabi-v7a'. The new Android kit appears as a new tab below the upper toolbar. Select 'build' in the tab, verify the build directory, and add '-j8' in the Make options as additional command line argument (this will enable 8-core compiling).

12. Run the application

Press the green button to compile and run the application as usual. You will have the choice to select the AVD or the real device (if connected). Note that the AVD needs a lot of time (two minutes) to start. Moreover, it is more likely to crash. If you a re using a real device the application is automatically deployed and installed on the device. Once running, you can detach the USB cable and test the application.

Joomla templates by a4joomla