7 min read

This article by Ray Rischpater, the author of the book Application Development with Qt Creator Second Edition, focusses on setting up Qt Creator for Android.

Android’s functionality is delimited in API levels; Qt for Android supports Android level 10 and above: that’s Android 2.3.3, a variant of Gingerbread. Fortunately, most devices in the market today are at least Gingerbread, making Qt for Android a viable development platform for millions of devices.

Downloading all the pieces

To get started with Qt Creator for Android, you’re going to need to download a lot of stuff. Let’s get started:

  1. Begin with a release of Qt for Android, which was either. For this, you need to download it from http://qt-project.org/downloads.
  2. The Android developer tools require the current version of the Java Development Kit (JDK) (not just the runtime, the Java Runtime Environment, but the whole kit and caboodle); you can download it from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html.
  3. You need the latest Android Software Development Kit (SDK), which you can download for Mac OS X, Linux, or Windows at http://developer.android.com/sdk/index.html.
  4. You need the latest Android Native Development Kit (NDK), which you can download at http://developer.android.com/tools/sdk/ndk/index.html.
  5. You need the current version of Ant, the Java build tool, which you can download at http://ant.apache.org/bindownload.cgi.

Download, unzip, and install each of these, in the given order. On Windows, I installed the Android SDK and NDK by unzipping them to the root of my hard drive and installed the JDK at the default location I was offered.


Setting environment variables

Once you install the JDK, you need to be sure that you’ve set your JAVA_HOME environment variable to point to the directory where it was installed. How you will do this differs from platform to platform; on a Mac OS X or Linux box, you’d edit .bashrc, .tcshrc, or the likes; on Windows, go to System Properties, click on Environment Variables, and add the JAVA_HOME variable. The path should point to the base of the JDK directory; for me, it was C:Program FilesJavajdk1.7.0_25, although the path for you will depend on where you installed the JDK and which version you installed. (Make sure you set the path with the trailing directory separator; the Android SDK is pretty fussy about that sort of thing.)

Next, you need to update your PATH to point to all the stuff you just installed. Again, this is an environment variable and you’ll need to add the following:

There are two different components/subsystems shown in the diagram. The first is YARN, which is the new resource management layer introduced in Hadoop 2.0. The second is HDFS. Let’s first delve into HDFS since that has not changed much since Hadoop 1.0.

  • The bin directory of your JDK
  • The androidsdktools directory
  • The androidsdkplatform-tools directory

For me, on my Windows 8 computer, my PATH includes this now:

…C:Program FilesJavajdk1.7.0_25bin;C:adt-bundle-
windows-x86_64-20130729sdktools;;C:adt-bundlewindows-x86_64-
20130729sdkplatform-tools;…

Don’t forget the separators: on Windows, it’s a semicolon (;), while on Mac OS X and Linux, it’s a colon (:).

An environment variable is a variable maintained by your operating system which affects its configuration; see http://en.wikipedia.org/wiki/Environment_variable for more details.

At this point, it’s a good idea to restart your computer (if you’re running Windows) or log out and log in again (on Linux or Mac OS X) to make sure that all these settings take effect. If you’re on a Mac OS X or Linux box, you might be able to start a new terminal and have the same effect (or reload your shell configuration file) instead, but I like the idea of restarting at this point to ensure that the next time I start everything up, it’ll work correctly.

Finishing the Android SDK installation

Now, we need to use the Android SDK tools to ensure that you have a full version of the SDK for at least one Android API level installed. We’ll need to start Eclipse, the Android SDK’s development environment, and run the Android SDK manager. To do this, follow these steps:

  1. Find Eclipse. It’s probably in the Eclipse directory of the directory where you installed the Android SDK. If Eclipse doesn’t start, check your JAVA_HOME and PATH variables; the odds are that Eclipse will not find the Java environment it needs to run.

  2. Click on OK when Eclipse prompts you for a workspace. This doesn’t matter; you won’t use Eclipse except to download Android SDK components.
  3. Click on the Android SDK Manager button in the Eclipse toolbar (circled in the next screenshot): Application Development with Qt Creator - Second Edition
  4. Make sure that you have at least one Android API level above API level 10 installed, along with the Google USB Driver (you’ll need this to debug on the hardware).
  5. Quit Eclipse.

Next, let’s see whether the Android Debug Bridge—the software component that transfers your executables to your Android device and supports on-device debugging—is working as it should. Fire up a shell prompt and type adb. If you see a lot of output and no errors, the bridge is correctly installed. If not, go back and check your PATH variable to be sure it’s correct.

While you’re at it, you should developer-enable your Android device too so that it’ll work with ADB. Follow the steps provided at http://bit.ly/1a29sal.

Configuring Qt Creator

Now, it’s time to tell Qt Creator about all the stuff you just installed. Perform the following steps:

  1. Start Qt Creator but don’t create a new project.

  2. Under the Tools menu, select Options and then click on Android.
  3. Fill in the blanks, as shown in the next screenshot. They should be:
    • The path to the SDK directory, in the directory where you installed the Android SDK.
    • The path to where you installed the Android NDK.
    • Check Automatically create kits for Android tool chains.
    • The path to Ant; here, enter either the path to the Ant executable itself on Mac OS X and Linux platforms or the path to ant.bat in the bin directory of the directory where you unpacked Ant.
    • The directory where you installed the JDK (this might be automatically picked up from your JAVA_HOME directory), as shown in the following screenshot:
      Application Development with Qt Creator - Second Edition
  4. Click on OK to close the Options window.

You should now be able to create a new Qt GUI or Qt Quick application for Android! Do so, and ensure that Android is a target option in the wizard, as the next screenshot shows; be sure to choose at least one ARM target, one x86 target, and one target for your desktop environment:
Application Development with Qt Creator - Second Edition

If you want to add Android build configurations to an existing project, the process is slightly different. Perform the following steps:

  1. Load the project as you normally would.

  2. Click on Projects in the left-hand side pane. The Projects pane will open.
  3. Click on Add Kit and choose the desired Android (or other) device build kit.

The following screenshot shows you where the Projects and Add Kit buttons are in Qt Creator:
Application Development with Qt Creator - Second Edition

Building and running your application

Write and build your application normally. A good idea is to build the Qt Quick Hello World application for Android first before you go to town and make a lot of changes, and test the environment by compiling for the device. When you’re ready to run on the device, perform the following steps:

  1. Navigate to Projects (on the left-hand side) and then select the Android for arm kit’s Run Settings.

  2. Under Package Configurations, ensure that the Android SDK level is set to the SDK level of the SDK you installed.
  3. Ensure that the Package name reads something similar to org.qtproject.example, followed by your project name.
  4. Connect your Android device to your computer using the USB cable.
  5. Select the Android for arm run target and then click on either Debug or Run to debug or run your application on the device.

Summary

Qt for Android gives you an excellent leg up on mobile development, but it’s not a panacea. If you’re planning to target mobile devices, you should be sure to have a good understanding of the usage patterns for your application’s users as well as the constraints in CPU, GPU, memory, and network that a mobile application must run on.

Once we understand these, however, all of our skills with Qt Creator and Qt carry over to the mobile arena. To develop for Android, begin by installing the JDK, Android SDK, Android NDK, and Ant, and then develop applications as usual: compiling for the device and running on the device frequently to iron out any unexpected problems along the way.

Resources for Article:


Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here