Qt on Android Episode 2

Update: Qt on Android Episode 3 is available here

Update2: Here you can read also the Chinese version, thanks goes to

 

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:

SDK

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:

SDK1

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:

QTC

  • 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:

QTC1

  • Final step: Uncheck Warn when debugging “Release” builds.

Goto Tools->Option->Debugger settings page. The following image shows how it looks on my computer:

QTC2

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!

Share on FacebookTweet about this on TwitterShare on Google+
p5rn7vb

27 thoughts on “Qt on Android Episode 2

  1. Thank you! This is great article. Will it be possible to write similar things, setting up and pre-requisite, etc on Windows? Thanks.

  2. 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. 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:
    12:40:26: Running steps for project untitled2…
    12:40:26: Configuration unchanged, skipping qmake step.
    12:40:26: Starting: “make”
    make: Nothing to be done for `first’.
    12:40:26: The process “make” exited normally.
    12:40:26: Removing directory /home/iuliu/build-untitled2-Android_for_armeabi_v7a_GCC_4_8_Qt_5_2_1-Debug/android-build
    12:40:26: Starting: “make” INSTALL_ROOT=/home/iuliu/build-untitled2-Android_for_armeabi_v7a_GCC_4_8_Qt_5_2_1-Debug/android-build install
    cp -f -R /home/iuliu/untitled2/qml/untitled2 /home/iuliu/build-untitled2-Android_for_armeabi_v7a_GCC_4_8_Qt_5_2_1-Debug/android-build/assets/qml/
    install -m 755 -p “libuntitled2.so” “/home/iuliu/build-untitled2-Android_for_armeabi_v7a_GCC_4_8_Qt_5_2_1-Debug/android-build/libs/armeabi-v7a/libuntitled2.so”
    12:40:26: The process “make” exited normally.
    Error while building/deploying project untitled2 (kit: Android for armeabi-v7a (GCC 4.8, Qt 5.2.1))
    When executing step ‘Deploy to Android device’
    12:42:40: Elapsed time: 02:14.

    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?

  4. 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?

      • 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!

      • 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.

      • “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

        • 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.

  5. 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!

  6. 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

Leave a Reply

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


nine − 9 =