Skip to content

Qt on Android Episode 2 - How to set up the development environment for Qt on Android

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:

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!

FacebookTwitterLinkedInEmail

36 thoughts on “Qt on Android Episode 2”

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

  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?

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

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

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

          1. I will try them after I get back from work and let you know if it worked.
            Thank you so much for the support!

  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?

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

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

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

      3. “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

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

  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

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

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

  8. 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 :/

    16:02:01: Running steps for project android…
    16:02:01: Configuration unchanged, skipping qmake step.
    16:02:01: Starting: “/usr/bin/make”
    /home/schnj/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ –sysroot=/home/schnj/android-ndk-r10e/platforms/android-9/arch-arm/ -Wl,-soname,libandroid.so -Wl,-rpath=/home/schnj/Qt/5.4/android_armv7/lib -Wl,–no-undefined -Wl,-z,noexecstack -shared -o libandroid.so main.o qrc_qml.o -L/home/schnj/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -L/home/schnj/android-ndk-r10e/platforms/android-9/arch-arm//usr/lib -L/home/schnj/Qt/5.4/android_armv7/lib -lQt5Quick -L/opt/android/ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -L/opt/android/ndk/platforms/android-9/arch-arm//usr/lib -lQt5Widgets -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGLESv2 -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
    16:02:01: The process “/usr/bin/make” exited normally.
    16:02:01: Removing directory /home/schnj/QT-Projects/build-android-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug/android-build
    16:02:01: Starting: “/usr/bin/make” INSTALL_ROOT=/home/schnj/QT-Projects/build-android-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug/android-build install
    /home/schnj/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ –sysroot=/home/schnj/android-ndk-r10e/platforms/android-9/arch-arm/ -Wl,-soname,libandroid.so -Wl,-rpath=/home/schnj/Qt/5.4/android_armv7/lib -Wl,–no-undefined -Wl,-z,noexecstack -shared -o libandroid.so main.o qrc_qml.o -L/home/schnj/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -L/home/schnj/android-ndk-r10e/platforms/android-9/arch-arm//usr/lib -L/home/schnj/Qt/5.4/android_armv7/lib -lQt5Quick -L/opt/android/ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -L/opt/android/ndk/platforms/android-9/arch-arm//usr/lib -lQt5Widgets -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGLESv2 -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
    install -m 755 -p “libandroid.so” “/home/schnj/QT-Projects/build-android-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug/android-build/libs/armeabi-v7a/libandroid.so”
    install: cannot stat ‘libandroid.so’: No such file or directory
    make: [install_target] Error 1 (ignored)
    16:02:01: The process “/usr/bin/make” exited normally.
    16:02:01: Starting: “/home/schnj/Qt/5.4/android_armv7/bin/androiddeployqt” –input /home/schnj/QT-Projects/build-android-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug/android-libandroid.so-deployment-settings.json –output /home/schnj/QT-Projects/build-android-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug/android-build –deployment bundled –android-platform android-22 –jdk /usr/lib/jvm/java-7-openjdk-amd64 –ant /usr/bin/ant
    Cannot find application binary /home/schnj/QT-Projects/build-android-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug/libandroid.so.
    16:02:01: The process “/home/schnj/Qt/5.4/android_armv7/bin/androiddeployqt” exited with code 2.
    Error while building/deploying project android (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.4.1))
    When executing step “Build Android APK”
    16:02:01: Elapsed time: 00:00.

    1. 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)

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

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

Leave a Reply

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