Freitag, 21. Juni 2013

Qt 5 on Android - getting started

For our master thesis we need a quite easy way to create applications for different platforms and systems. For now the main targets are Windows, Linux and Android. The simplest way would be HTML5. It should run here, there and probably everywhere. But the performance isn't that great for what we want to achieve. Java could be an option as long as we won't go in the direction of Apple. Another option is the use of something like Unity3D. But it is big, clunky and I won't be able to develop with it from my Linux machine.


A much better approach is the use of Qt. With Qt 5 Android and iOS will be supported directly from the Qt SDK. Before you had to use an external extension to make it work.
Just write your blazing fast C++ code for the back-end and use QML and JavaScript code for the front-end and scripting. Write it once and export and use it on all supported platforms.


For now Qt says that Android support is more of a "technology preview" and the current Qt version to use for it is still beta. But it works!

So how to get started?

You need some things to install. ADT, NDK, Qt, Ant, JDK, (Creator, Compiler, ...). Some setup. It's easier then you might think.

The newest version of Qt is 5.1 which is currently in RC1 stage. Here is a list of new features:

You might also wanna look at possible problems that might be still in there:

Announcement of Qt 5.1 RC1:

I took the online installer for Linux 64Bit:

Those are the things I installed:
If you don't have an Android device around you should prefer the Android x86 version because with some tricks you can make your emulator hardware accelerated and therefore it works much better then the armv7 version. You'll find more information and how to setup your tools right here:

You also need the Android Developer Tools - ADT from:

And the Native-Code Development Kit - NDK from:

The Qt 5 for Android page (http://qt-project.org/wiki/Qt5ForAndroidBuilding) says that you should use a custom NDK version from http://code.google.com/p/mingw-and-ndk/downloads/list . For now I used the official NDK and haven't had a problem. But who knows…

For Linux the ADT and the NDK are just archives that want to be extracted. On my installation it looks like this:

Also you should have a working installation of ant and the Java JDK. You could install those via:
aptitude install ant openjdk-7-jdk
That should be all you need.
To build and test your application on you desktop you should have clang and gcc installed. So you might want to do something like:
aptitude install clang-3.3 llvm-3.3-dev g++-4.8 

The Qt Creator that comes with Qt 5.1 should be OK. But there is also a newer beta version out there:
http://blog.qt.digia.com/blog/2013/05/30/qt-creator-2-8-0-beta-released/


Let's start building!

There are just some configurations left. Do make those we need the Qt Creator running.
Go to
Tools → Options → Android
The Ant and JDK locations should be set automatically. If not, check if you have them installed correctly.
The Android SDK and NDK locations you need to set yourself. For me those two locations are
~/projects/Qt/adt-bundle-linux-x86_64-20130219/sdk
~/projects/Qt/android-ndk-r8e 

The following changes are needed in the "Build & Run" section.
Specify where the Qt version are,

compilers should be found automatically,

most kits should also be ready automatically. I just needed to add kits for my desktop environment.


The first Android app

Now you are ready to create your first Android app. Create a new project under
File → New File or Project → Applications → Qt Quick 2 Application (Build-in Types)

Plug you Android device to you computer. Be sure to also have set up your device correctly so that it allows the connection.
Check your settings so it will build for arm.
And then: Push the big "Run" button.

The project will be build, deployed to your device and there executed.
You device should look like this now:

If you get some build errors then check out this site: http://qt-project.org/wiki/Building_Qt_5_from_Git
I needed e.g. libglu1-mesa-dev and some of the libxcb ones.

The first test project I did I named "1". Somehow I couldn't get it on the device. I don't know why. Maybe the name was not allowed. The second test I named "Simple_test" and that made it working.

Another "thing" I encountered is the way the Qt packages get on the device. In the
Project → Run → Deploy configuration
you can choose which Qt libraries to use and where they should come from.

The standard is "Use Qt libraries from device" and "Use local Qt libraries". For a simple TicTacToe game I made it worked without problems. 
Without the check on "Use local Qt libraries" when starting you app it will ask you to install Ministro:
https://play.google.com/store/apps/details?id=org.kde.necessitas.ministro&hl=de

Those are the standard libraries for your android device and should work best. Also they just need to be installed once and every other Qt based app will just use them.


In short

  1. Get 
    1. Qt 5.1 (http://download.qt-project.org/online/qt5/online_installers/), 
    2. ADT (http://developer.android.com/sdk/index.html), 
    3. NDK (http://developer.android.com/tools/sdk/ndk/index.html), 
    4. Ant, JDK, GCC/Clang, (other development files …)
  2. Install Qt, extract ADT & NDK
  3. Setup Qt Creator to use ADT & NDK, Qt versions, compiler, kits
  4. Build and deploy your Qt app for Android
  5. Have fun!

Keine Kommentare:

Kommentar veröffentlichen

[Review/Critic] UDock X - 13,3" LapDock

The UDock X - 13.3" LapDock is a combination of touch display, keyboard, touch-pad and battery. It can be used as an extension of vari...