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:
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!
- OpenSUSE 11.4 Milestone 5 x86_64
- Qt SDK 1.1 Technology Preview: http://labs.qt.nokia.com/2011/01/20/qt-sdk-1-1-technology-preview-released/
- Android NDK: http://developer.android.com/sdk/ndk/index.html
- Android SDK: http://developer.android.com/sdk/index.html
- Android Lighthouse: http://gitorious.org/~taipan/qt/android-lighthouse
- Android Qt Creator: http://gitorious.org/~taipan/qt-creator/android-qt-creator
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.
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:
Remember you'll need root privileges for operating in /usr/local.
Again, download it and put it in $HOME/local/ and link it as well:
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:
save it, then make bash reload it by typing:
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".
Enter your $HOME/local directory and clone the repository:
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.
# 4 - android 1.6
# 5 - android 2.0 & 2.1
# 8 - android 2.2
# 9 - android 2.3
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
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 :
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):
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:
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!
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! :)