Update: Qt on Android Episode 3 is available here.
Update2: Here you can read also the Chinese version, thanks goes to Foruok.
In this article we'll move forward and see how to set up the development environment for Android.
A few remarks before we start:
- This article focuses on Qt 5.2! I'll add comments for 5.1 though.
- Even you can use Windows and Mac OSX to develop Android Qt apps, for a painless experience I do recommend GNU/Linux. For the rest of the article I'll refer only to GNU/Linux. Mac OSX setup should be pretty close to GNU/Linux.
Now, let's get started:
Pre-Requirements:
- a GNU/Linux box :)
- ant
- (open)JDK 6+. If you are using 5.1 and Qt Creator 2.8 make sure you are using (open)JDK 6 and not 7!
On a debian based distribution the following command does the job:
sudo apt-get install ant openjdk-6-jdk
Install:
Next step is to download and install the Qt Project SDK. If you are reading this article *before* Qt 5.2 is released and you want to use Qt 5.2 then you have to download a copy from here http://download.qt-project.org/snapshots/qt/5.2/. Otherwise if Qt 5.2 is released or you want to use Qt 5.1 then you should use http://qt-project.org/downloads to download one.
If you choose an offline installer, don’t forget to choose one which contains Android in its name. If you prefer the online installer, make sure you check the Android component(s).
Qt Project's SDK is not coming with Android SDK/NDK so you must download and install them yourself from http://developer.android.com/sdk/index.html. You'll need Android NDK (ver. r9+) and SDK (ver. 22+).
If you don't plan to create Android Java apps, then make sure you are downloading ONLY the SDK and not ADT Bundle or Android Studio, check the following image:
Setup:
After you download and extract them, you have to install at least Android API-13! No, I don't (and never did) smoke crack, and yes, I know you want to target lower API's! Short version is: just do it:), you'll still be able to target Android devices starting with API-9! Longer version is in the next article where I'll give you a detailed explanation on this matter.
So, to install an Android API SDK you need to run:
android-sdk/tools/android
tool and choose Android API-13 SDK Platform. You also must install Android SDK Platform-tools and Android SDK Build-tools. You can choose extra Android APIs if you are planning to extend your application using JNI and you target a specific API version. For the moment Android API-13 SDK is enough. If you are superstitious and you are afraid of the beautiful prime number 13 you can choose any greater version :).
The next image shows you what I chose:
If you are using a real device on GNU/Linux, you have to set the USB permissions. Please check Android http://developer.android.com/tools/device.html or your distribution site on this matter.
In order to make sure you've set the USB permission correctly, first enable USB debugging on your device, then plug it on your computer and check the output of the following command:
android-sdk/platform-tools/adb devices
If you'll see your device listed there, then you are in luck! You've successfully set up the USB permissions correctly. If not, then you will have to search more on the net :).
Starting this step the GNU/Linux becomes trouble free!
In the end, we'll see how to set up the Qt Creator for Android
- Step one: fill android settings page.
Open Qt Creator. Goto Tools->Option->Android settings page and set Android SDK and NDK locations. Also make sure Automatically creates kits for Android tool chains is checked! The following image shows you how Android settings page looks on my computer:
- Step two: check if Qt Creator created the Android kits.
Goto Tools->Option->Build & Run settings page, and click on Kits tab.The following image shows how it looks on my computer:
- Final step: Uncheck Warn when debugging "Release" builds.
Goto Tools->Option->Debugger settings page. The following image shows how it looks on my computer:
Enjoy!
Now is the time to see if everything we've setup works well. To do that, open Qt Creator and create a new project. QWidget based or QML, it doesn't matter. Just make sure you are choosing an Android KIT when you are creating it.
Hit the road Jack! OH, I mean hit the run button :) ! Qt Creator 3.0 (the one that comes with Qt 5.2 SDK) should popup a dialog with all compatible devices that are connected to your computer. Choose one device and continue. If your device isn't there, then make sure you have read and followed the setup step from this article. In a few seconds your application should run on your device.
See you next time when we’ll discuss in detail how to use Qt Creator for Android to: create, deploy, debug and sign Qt apps for Android.
Thank you for your time!
36 Comments
23 - Nov - 2013
sarigalin
Hi, Thanks for your Qt on Android posts. I am eagerly waiting for next episode, Good luck
20 - Dec - 2013
Girija
Hi,
Thanks for this article. It is very useful for people like me.
17 - Jul - 2017
rousing
Hello Can you update the guide with the current version of Android & Qt please ? it's one of the more valuable paper on this topic. thank you.
21 - Jan - 2014
Sys
The expert! I am also waiting for episode 4. Thanks!
21 - Jan - 2014
BogDan Vatra
Please check first episode 3 before episode 4 :)
http://www.kdab.com/qt-android-episode-3/
23 - Jan - 2014
Ryocchin
Thank you! This is great article. Will it be possible to write similar things, setting up and pre-requisite, etc on Windows? Thanks.
24 - Jan - 2014
foruok
My Chinese version of Qt on Android Episode 2: http://blog.csdn.net/foruok/article/details/18726943
29 - Jan - 2014
meysam
in the name of Allah Thank you so much for this useful article. best regards
2 - Mar - 2014
Oleg Ratsa
Be careful with «Automatically create kits for Android tool chains» option. It uses translation and creates kits with names on current locale. For example, in russian, it will be "Android для armeabi-v7a..." instead of english version "Android for armeabi-v7a...". Non english characters and spaces makes android compilator to fail on builds and installs.
3 - Mar - 2014
BogDan Vatra
Hmm ... strange, I'll check it ASAP. Thanks for letting me know about it!
12 - Apr - 2014
Iuliu
Hello Bogdan, Thanks for the tutorial. I followed it but I can't by, any means, deploy my app :( FIrst I had a problem regarding the AVDs which were all incompatible. I solved it by adding ANDROID_TARGET_ARCH = default/armeabi-v7a variable in QtCreator -> Projects -> BuildEnvironment.
And after building I get:
Can you please give me a solution or point me to a solution, it's been a week since I'm trying to make it work?
13 - Apr - 2014
BogDan Vatra
It is a known bug, introduced by the newest Android SDK. Please don't change ANDROID_TARGET_ARCH, it will break your compilation!
To fix it you have the following options: - Find an older Android SDK. - Upgrade your Qt creator (use Qt SDK 5.3 beta) - Use a real device.
13 - Apr - 2014
Iuliu
Thank you so much for the reply.
Is it possible to recommend me an Android SDK that works well with Qt 5.2.1? Also, another question, AFAIK the last QtCreator is 3.0.1. Is it ok to use QtCreator 3.0.1 with QtSDK 5.3? Because I couldn't find a newer version of QtCreator on qt-project.org, not even beta. So is it necessary to use a newer version of QtCreator as well?
13 - Apr - 2014
Iuliu
I did upgrade to QtSDK 5.3 and QtCreator 3.0.82 by downloading qt-opensource-linux-x64-android-5.3.0-beta.run from http://download.qt-project.org/development_releases/qt/5.3/5.3.0-beta/ and I successfully built a default qt quick project but when I run the application(which would also deploy it) I get the window with ABIs and all the devices are under "Incompatible devices" category. The message is "ABI is incompatible, device supports ABIs: default/armeabi". I have the latest Android SDK and Android NDK and I also installed everything in the above tutorial. Any hints? I really want to make this working!
Thank you!
14 - Apr - 2014
BogDan Vatra
try to download one of the RC snapshots from here http://download.qt-project.org/snapshots/qt/5.3/5.3.0-RC/2014-04-14_55/
14 - Apr - 2014
Iuliu
I will try them after I get back from work and let you know if it worked. Thank you so much for the support!
14 - Apr - 2014
Iuliu
So I downloaded qt-opensource-linux-x64-android-5.3.0-RC_2014-04-14_00-48-35-55.run from http://download.qt-project.org/snapshots/qt/5.3/5.3.0-RC/2014-04-14_55/ and the deploy worked successfully!
Thank you so much!
21 - Apr - 2014
Iuliu
I just upgraded to Ubuntu 14.04 and when I try to run a basic Qt Quick application I get "W/EGL_emulation( 1269): eglSurfaceAttrib not implemented" after it launches. The result is a quick filcker of the application after which the screen turns black. I read online that this could be an Android related issue, any hints on what could be the reason of this behavior?
23 - Apr - 2014
BogDan Vatra
Make sure your Ubuntu has the opengl properly setup and you AVD is using the HOST GPU. My guess is that your opengl drivers are not setup correctly.
25 - Apr - 2014
Iuliu
You were right! What I did was I "add-apt-repository ppa:oibaf/graphics-drivers" which I found here https://launchpad.net/~oibaf/+archive/graphics-drivers/ and then I " apt-get install xserver-xorg-video-intel".
The "W/EGL_emulation( 1289): eglSurfaceAttrib not implemented" message is still appearing but the application works fine.
Mersi mult! :)
26 - Apr - 2014
Iuliu
Unfortunately it worked only once. It's very strange. I removed my android sdk and ndk folders, downloaded the sdk and ndk again and installed the necessary packages and ran the application and it worked. Then I closed it and ran it again and it crashed just like before then couldn't make it work again.
Could it really be because of the OpenGL drivers?
I ran "glxgears" and they seem to work fine at 60 - 69fps. I also ran "/usr/lib/nux/unity_support_test -p" and I got:
OpenGL vendor string: Intel Open Source Technology Center OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile OpenGL version string: 3.0 Mesa 10.1.0 Not software rendered: yes Not blacklisted: yes GLX fbconfig: yes GLX texture from pixmap: yes GL npot or rect textures: yes GL vertex program: yes GL fragment program: yes GL vertex buffer object: yes GL framebuffer object: yes GL version is 1.4+: yes Unity 3D supported: yes
which seems fine because I don't have any dedicated graphics card and on Ubuntu 13.10 it worked fine on the same hardware.
I'm sorry for asking for help here but I couldn't find any other people having the same issues anywhere on the web :(
Thank you!
26 - Apr - 2014
Iuliu
So I installed "Qt Online Installer for Linux 64-bit" from qt-project.org and it seems to work well :)
I hope it is not a temporary success.
2 - Jun - 2014
wally
"W/EGL_emulation( 1951): eglSurfaceAttrib not implemented"
I'm trying to solve this error on a QtCreator environment on OpenSuse13.1. How to check OpenGL is properly setup ? glxgears works nice on a nvidia card. And ... How to make sure my AVD is using the HOST GPU ? thank you
3 - Jun - 2014
BogDan Vatra
You need to use Android AVD Manager. You can start it from QtCreator: Tools->Options->Android->Start AVD Manager. Edit the AVD and check if it has "Use Host GPU" is checked.
19 - May - 2014
Emil
I've been struggling for two days to deploy an application on Android. After reading this it all became so easy :) . Thank you very much!
23 - May - 2014
Bartłomiej Makowski
Hi,
It is really nice tutorial. Qt for Android is great. The only thing I have problems with is debugging.
Is it working for you? I tested on small example project on GNU/Linux Ubuntu, Fedora and it works. But when I try to debug a bigger project I get "Debugging failed".
And I tried also on MacOS X and I always get "Debugging failed".
I have tested Qt 5.2 and 5.3.
Do you have the same experience?
Best Regards, Bartek
26 - May - 2014
BogDan Vatra
I'm using QtCreator to debug Qt itself (most of the modules) and I didn't had any problems. If your project is huge try to use a 64bit NDK on a 64 bit GNU/Linux environment. If it still doesn't work, then open the "Debugger log" view, rerun the application and report the problem here: http://bugreports.qt-project.org together with the debugging log.
28 - May - 2014
Bartłomiej Makowski
Thank you! That helped!
11 - Aug - 2014
Vuong
Hello Bogdan, thanks for nice tutorial. I'm developing a Browser application on Android platform. But QtWebkit doesn't support for Android. I found this example to use native web example. https://code.google.com/p/qt-android-native-web-view-example/ I depend on this example to program my app but use Qml. But I have a trouble with mainwindow class. I cann't create a webview because I don't know how to create an UI to attach webview on it. Is that right?
29 - May - 2015
Gram
Thank you very much for this nice Tutorial. It helped me a lot. Unfortunately my Qt cant Build any Android projects. Maybe you can help me out here :/
2 - Jun - 2015
BogDan Vatra
First and foremost do NOT name your application android! Then try a very simple QtQuick application (new project ->QtQuick[Controls]) and name it anything but android (e.g. test1)
15 - Jun - 2015
Hamid
First of all thanks a lot Sir. I followed your procedure and set up the environment but when i am compiling the code for armeabi and armeabiv-7a, i am getting a lot of errors. like template argument 1 is invalid from file type_traits. This file is added from android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/type_traits and also errors like not defined from cstdlib and smath. All the files are includes from android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include. Any suggestion?
16 - Jun - 2015
BogDan Vatra
Hmm, strange... Make sure your application compiles on desktop then try it on Android. If the problem persists please provide us the full lon on #necessitas on the Freenode IRC servers.
14 - Jul - 2015
Bo.Yang
Hey,man,when I Deployment,The Question :[install_target] Error 1(ignored),why?please
14 - Jul - 2015
Bo.Yang
"Ctrl+B" is Ok,but "Ctrl+R" could not pass
15 - Jul - 2015
BogDan Vatra
Try to read also http://www.kdab.com/qt-android-episode-3