Objectives : compile a Vala application under Linux, targeting Android.

We have a Vala console application, without any additional libraries.

We want to create an Android version of it without modifying the source code.

(PS : the targeted phone/tablet needs to be "rooted" and to have an installed terminal emulator)







Prerequisites

A Linux Debian or Ubuntu distro, with Vala installed.

To install Vala, please read this previous article, part 1).





1) Install the compilation toolchain

- Download the Android NDK r7b for Linux :

android-ndk-r7b-linux-x86.tar.bz2 (61.3 Mb)

(and extract it to "/opt" :

mv android-ndk-r7b-linux-x86.tar.bz2 /opt

cd /opt

tar xfvj android-ndk-r7b-linux-x86.tar.bz2)

- Download the agcc script (thanks to Giulio Lunati for his work) :

agcc.pl (5 Kb)

(et install it to "/opt", making it executable :

mv agcc.pl /opt

chmod a+x /opt/agcc.pl

ln -s /opt/agcc.pl /usr/bin/agcc)

- Configure these environment variables (either by adding these commands at the end of "/etc/profile" then rebooting, either by typing them directly in a terminal) :

export NDK=/opt/android-ndk-r7b

export PATH=$PATH:/opt/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin





2) Install the GLib libraries for Android

- Download GLib 2.28.1 for Android :

glib-2.28.1-android_(TARNYKO).tar.bz2 (1.81 Mb)

(and extract them to a new "/opt/android" folder :

mkdir /opt/android

mv glib-2.28.1-android_\(TARNYKO\).tar.bz2 /opt/android

tar xfvj glib-2.28.1-android_\(TARNYKO\).tar.bz2)





3) Compile

- We will tell "pkg-config" to locate Android libraries in our custom path :

export PKG_CONFIG_PATH=/opt/android/lib/pkgconfig

We are ready ! We will use some Vala source code (not using any additional library).

- Compile :

valac --cc=agcc -o myprogram myprogram.vala

A new executable (here myprogram) should have been created if everything went well.

It won't run on our Linux system, because it's targeting Android !





4) Release

- Create a folder containing the binary and all library files (.so) found in this archive :

unzip glib-2.28.1-android_runtime_(TARNYKO).zip

mkdir ~/distri

cp myprogram ~/distri

cp *.so.* ~/distri

- Connect your Android tablet/phone to your computer. Using the adb program, which you naturally already have on your system :-), send these files one by one to a directory of the device :

adb remount

adb push monprogramme /system

adb push libasprintf.so.0 /system

adb push libgio-2.0.so.0 /system

...

adb push libintl.so.8 /system





5) Run

- On the device itself, open a terminal, add the program path to a var and run it !

export LD_LIBRARY_PATH=/system

cd /system

./myprogram

Well done !