Harbour and Qt on Android part 1

PLEASE NOTE: These are instructions on how I setup my dev machine on APRIL 2 2014! I used the directories and the setup I think are better suited for my development!!! If you don’t have a standard or want to follow my next posts please use the same dir tree.

Prepare the dir tree

I will put all the stuff related to Harbour on Android inside c:\android directory. This will include standard x86 Harbour, Harbour for android, android SDK and NDK.

Qt and Java will be installed in default directories so that they will be available systemwide.

Download and install Java JDK

Download and install Java JDK as usual (you may already have it on your pc)

Download and install Qt 5.2

Go to http://qt-project.org/downloads and download “Qt 5.2.1 for Android (Windows 32-bit, 1.1GB)”.

This is the version available on april 2, 2014.

Install it using default dir (c:\qt\qt5.2.1). In “Select Components” open Tools and select MinGW 4.8. As I said this is a system-wide installation of Qt and this compiler will be used to develop windows based programs. In the past I also installed Qt source code but I don’t do anymore…

Proceed with installation but do not launch Qt Creator at the end.

Download & unzip SDK and NDK

Go here https://developer.android.com/sdk/index.html?hl=sk and download ADT bundle (button on the right). It’s a 510 MB zip download.

On the left menu click on “Download NDK” and download it. It’s another 496 zip download.

Unzip both files into c:\android and shorten the dir names. I prefer to keep the reference to the version instead of using names like sdk or ndk. For your reference at the end you should have these dirs:


Go to c:\android\20140321 directory and run SDK Manager application. It will take some seconds to start (it’s java) and it will propose to install a couple of programs (Android support Library and Google USB drivers) and upgrade a couple more (depending on the installed ADT).

Open the Android 4.3 (API18) and select SDK Platform and ARMEABI v7a System Image.

Proceed to install.

Download & unzip ant

Download Apache ant from http://ant.apache.org

Unzip into c:\android so that you have the following dir tree (versions may change, one level of dir must be removed):


Setup Qt Creator

Configure directories

Start Qt Creator. Menu Tools -> Options.

On the leftmenu click on “Android”. On the right panel browse and select the folders requested.

The values should be:

Android SDK location: C:\android\20140321\sdk
Android NDK location: C:\android\r9d
Ant location: C:\android\apache-ant-1.9.3\bin\ant.bat   (it was autodiscovered in my setup)
JDK location: C:\Program Files\Java\jdk1.7.0_45

Click on Apply button.

Configure test devices

Click on Start Android AVD Manager, it will open a new window. Click on New and crete a new device. I usually create a generic tablet and a phone.

AVD Name: Tablet
Device: 10.1" WXGA
Target: Android 4.3 - API Level 18
CPU/ABI: ARM (armeabi-v7a)  (autoselected)
Skin: Skin with dynamic hardware controls
Check Use Host GPU


AVD Name: Phone
Device: Nexus S
Target: Android 4.3 - API Level 18
CPU/ABI: ARM (armeabi-v7a)  (autoselected)
Skin: Skin with dynamic hardware controls
Check Use Host GPU

It is possible to create specific devices but it can be done later. Close the Android AVD Manager. To make the new devices appear on the list, click the Add button under the Start Android AVD Manager button, and then click Cancel. The devices Tablet and Phone should appear in the list. Click Apply and the Ok to close the configuration window.

To solve a problem introduced by the new Android SDK, waiting for the new Qt to adapt, it is necessary to add an environment variable to our operating system.

    ANDROID_TARGET_ARCH     default/armeabi-v7a

Since this env variable must be available to programs running from the gui, I added it in the system environment variables as in this picture (you have to find it in your operating system and language):

Compile Harbour & Harbour for android

Clone Harbour source code (see http://www.mozzarellaincarrozza.it/harbour/compiling-harbour-for-qt-from-git/) but clone it in this way:

cd \android
git clone https://github.com/harbour/core.git Harbour

Check you have this dir tree:


We now have to compile standard Harbour and then Harbour for android.

First of all we need to set some env variables. I don’t use system-wide env settings so that I can have multiple Harbour and qt versions on the same workstation. I use batch files to set them.

Save this script into c:\android\harbour with name set_android.bat and run it:

SET QT_PLUGIN_PATH=C:\Qt\qt5.2.1\5.2.1\mingw48_32\plugins
SET HB_WITH_QT=C:\qt\qt5.2.1\5.2.1\mingw48_32\include
rem HB_QT_MAJOR_VER can probably become deprecated in next
rem Harbour/qtcontribs releases.

Then run win-make and wait while standard Harbour is compiled.

cd \andorid\Harbour

Since this is a Harbour that is used only for android, we may avoid compiling contribs to save time/space…

When compilation is completed, copy and paste the build_cross_android.bat file listed below and store it in c:\android\harbour. The original script is from Przemek. The script must be updated to point to the right directories.

Run build_cross_android.bat. The script will compile a cross-compiled version of Harbour for android that is installed in the same tree.

The script will also create a new script to be used to cross-compile.
PLEASE NOTE: the script creates file hbmk2a.bat in c:\android\harbour directory. Please copy the file into c:\android\harbour\bin\win\mingw so that it is under PATH.

rem @echo off
rem Original version of this script by Przemek
rem Please change directory names

set NDK=C:\android\r9d
set QT=C:\Qt\Qt5.2.1\5.2.1\android_armv7\include
rem set HB_INSTALL_PREFIX=C:\android\hb.android

rem set LVL=3
set LVL=9
rem set LVL=14

set CPU=arm
rem set set CPU=x86
rem set set CPU=mips

rem set CCOMP=4.6
set CCOMP=4.8

set PLATFORM=android-%LVL%
set HOST_CPU=windows-x86_64

set SYSROOT=%NDK%\platforms\%PLATFORM%\arch-%CPU%

if "%CPU%" == "arm"  set TCHAIN=arm-linux-androideabi
if "%CPU%" == "mips" set TCHAIN=mipsel-linux-android
if "%CPU%" == "x86"  set TCHAIN=x86

set HB_PLATFORM=android
set HB_COMPILER=gccarm
set HB_CCPREFIX=%NDK%\toolchains\%TCHAIN%-%CCOMP%\prebuilt\%HOST_CPU%\bin\%TCHAIN%-



set HB_USER_CFLAGS=%HB_USER_CFLAGS% --sysroot=%SYSROOT% -I%NDK%\sources\cxx-stl\gnu-libstdc++\4.8\include -I%NDK%\sources\cxx-stl\gnu-libstdc++\4.8\libs\armeabi-v7a\include -I%NDK%\platforms\android-9\arch-arm\usr\include

if not "%1" == "clean" goto skip_clean
   win-make %1
win-make install %1 %2 %3 %4 %5 %6 %7 %8 %9 > log-%PLATFORM% 2> log-%PLATFORM%.err

set HBMK2A=%HB_INSTALL_PREFIX%\bin\hbmk2a.bat

echo @echo off> %HBMK2A%
echo.>> %HBMK2A%
echo set HB_WITH_QT=%QT%>> %HBMK2A%
echo set SYSROOT=%NDK%\platforms\%PLATFORM%\arch-%CPU%>> %HBMK2A%
echo.>> %HBMK2A%
echo.>> %HBMK2A%
echo.>> %HBMK2A%
echo.>> %HBMK2A%
echo hbmk2 -plat=android %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>> %HBMK2A%

4 thoughts on “Harbour and Qt on Android part 1

  1. Maurizio

    Hello ,
    Thanks very clear , I followed your note and works , I have problem when I compile harbour with build_cross_android.bat , doesn’t work .

    1. Francesco Post author

      Hi Maurizio,
      which kind of problems do you have ?

      Please note that a couple of days ago there was a commit in hbQt that may have changed something but not in building Harbour….

      1. Maurizio

        I solve , the problem was
        rem set HOST_CPU=windows-x86_64
        set HOST_CPU=windows


        1. Francesco Post author

          Are you using the 32 bit version of ndk ? If yes please confirm so that I can update the text


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>