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
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:
- a GNU/Linux box 🙂
- (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
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:
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:
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:
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:
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!