Twitter icon
Facebook icon
Google icon
StumbleUpon icon
Del.icio.us icon
Digg icon
LinkedIn icon
MySpace icon
Newsvine icon
Reddit icon
Technorati icon
Yahoo! icon
e-mail icon

Setting up Qt on Android - Part 1

omissis's picture

It's more or less one year now since I first had my eyes on the cool Qt framework. Until now, I enjoyed playing with it every now and then as a hobby, creating small demo applications for my own interest. What has always kept me a bit away from seriously engaging with them is their "limited" support for mainstream mobile platforms: iOs, Android and Blackberry. Unfortunaley, even if Nokia has hell of marketshare, we all agree they lost the first (and perhaps even the second) train for the Smartphone World Market Domination © and it seems they realized that. So, even if I totally fell in love with Qt way more than with iOS' or Android's SDKs, I've always been reluctant about seriously consider this platform because all in all clients use to ask for iPhone apps, with Android gaining real momentum in the last few months. This problem is made even worse by Nokia itself who doesn't want (from what I heard this summer @ See 2010) to officially support other mobile platforms than theirs and Windows', and they have all the rights to do that. There's hope for the future though, and it's called Lighthouse: http://labs.qt.nokia.com/2010/10/29/lighthouse-is-integrated/. What's all of this about is conveniently told in a few words by the project teaser on http://qt.gitorious.org/qt/lighthouse:

"Lighthouse is a research project that aims to make it easier to port Qt to different graphics systems. Conceptually it is “Qt for Embedded Linux without QWS”. Lighthouse is completely windowsystem-agnostic: all interfacing with window systems is done in plugins"

So here we are. This tutorial is the first of a series of two? three? four? about Qt and Android, and how to try not to get too mad after them, because one person(me :D) is already more than enough. Before starting, I assume you already have installed git and the development environment, which should include gcc, g++, ld, make, etc plus the glibc and the X11 libs. Let's begin with the requirements and settings then!

Operating System1:

  • OpenSUSE 11.4 Milestone 5 x86_64

Requirements summary:

Installing and compiling all the stuff

 

Qt SDK 1.1 Technology Preview

So let's start with the Qt SDK 1.1. Installing it should be quite straightforward, moreover you're able to choose between the online and the offline installer: they will both do the job with (hopefully :) no pain. I've chosen the offline one for no particular reasons, feel free to get the one that better suits your tastes, just pay attention to the installation path: I put it in $HOME/local/qtsdk-1.1-tp, any other location in your home directory should do.

Android NDK

This should be easy too, just download it and put it under /usr/local. Eventually you can create a link in order to have an easy-to-remember path:

ln -s /usr/local/android-ndk-r5 /usr/local/android-ndk

Remember you'll need root privileges for operating in /usr/local.

Android SDK

Again, download it and put it in $HOME/local/ and link it as well:

ln -s $HOME/local/android-sdk-linux_86 $HOME/local/android-sdk

Then I suggest you to add the SDK and NDK bin dirs to your $PATH environment variable in order to have the commands directly available in your terminal, so open your ~/.bashrc (or ~/.bash_profile) file and add:

export PATH=/usr/local/android-ndk:$HOME/local/android-sdk/tools:$HOME/local/android-sdk/platform-tools:$PATH

save it, then make bash reload it by typing:

source ~/.bashrc

Once you've done that, launch "android" and from there download the SDK Platforms you're interested into.



Then, create a virtual device with the specs of your choice.



You might also want to play around a bit with the Android SDK in order to become familiar with it; give a look here for more information: http://developer.android.com/guide/index.html, Among others, I recommend reading the "Developing > In Other IDEs" section to become familiar with the basic command line tools provided by the Android SDK, such as "adb" or "android".

Android Lighthouse

Enter your $HOME/local directory and clone the repository:

git clone git://gitorious.org/~taipan/qt/android-lighthouse.git

What you'll need to do now is to configure the androidconfigbuild.sh script to make it run properly on your machine, this is the one I used which is pretty similar to the default one, just ANDROID_NDK_ROOT and ANDROID_NDK_PLATFORM have been modified a bit and the "make install" has been removed.

#!/bin/sh # Please set the following evn vars correctly !!!
export ANDROID_NDK_ROOT=/usr/local/android-ndk
export ANDROID_NDK_HOST=linux-x86
export ANDROID_NDK_TOOLCHAIN_PREFIX=arm-linux-androideabi
export ANDROID_NDK_TOOLCHAIN_VERSION=4.4.3
export ANDROID_NDK_PLATFORM=android-5
# 4 - android 1.6
# 5 - android 2.0 & 2.1
# 8 - android 2.2
# 9 - android 2.3
make confclean
rm -fr include
rm -fr lib
git checkout lib
./configure -opensource -release -qpa -arch arm \
-no-phonon -freetype -fast -xplatform android-g++ \
-little-endian -no-qt3support -no-largefile \
-openssl -I $PWD/src/3rdparty/android/precompiled/$ANDROID_NDK_PLATFORM/arch-arm/include \
-L $PWD/src/3rdparty/android/precompiled/$ANDROID_NDK_PLATFORM/arch-arm/lib \
--prefix=/data/local/qt -shared \
-nomake demos -nomake examples -confirm-license -pch -exceptions \
-no-webkit -no-script -reduce-relocations -reduce-exports

#-jX where X is the number of CPU cores + 1
make -j5

Now that the file is fine, you can run it followed by a "sudo make install" that will run with root privileges and install the libs in /data :

./androidconfigbuild && sudo make install

The process should be quite straightforward and once completed, will give you the libraries ready for Android, so the only thing left to do here is to copy them to the virtual device(be sure to have the one previously created actually running):

mkdir andlibs
cp -a lib/*.so* andlibs/
adb push andlibs /data/local/qt/lib
rm -fr andlibs

Android Qt Creator

Last but not least, our favourite IDE. As for android-lighthouse, enter your $HOME/local directory and clone the repository:

git clone git://gitorious.org/~taipan/qt-creator/android-qt-creator.git

Simply open the qtcreator.pro with the standard Qt Creator provided with the Qt SDK 1.1, paying attention to use the correct Qt version, which is again the one provided by the Qt SDK 1.1(Desktop Qt for GCC (Qt SDK)).



Once you've open the project, just click on build and everything should run smooth. After some time(depending on your machine speed) it should finish to compile and you'll be finally able to run the long desired Android Qt Creator, which should reside in $HOME/local/qtcreator-build-desktop/bin. Et voilà! You should now have almost everything you need in place to build & deploy your shining Qt apps on Android2!



In the next tutorial we'll take a look at the compiler and how to tweak it to get our first app on the emulator, stay tuned!

References:

Dont' forget to regularly check the android-lighthouse project on google code and the google discussion group

Credits:

Special credits and thanks go to BogDan Vatra for his unvaluable work on the android-lighthouse project, I hope I'll be able to contribute more in the future! :)

Notes: