Using QtCreator on Linux to cross compile for Android

This is a log of setting up a development environment.  I am using Ubuntu 14.04.

My ultimate goal is to use pyqtdeploy to distribute a (Python, PyQt, Qt) app to Android (and iOS.)

Installing QtCreator

QtCreator is a cross platform IDE.  I have been using Eclipse and PyDev, but QtCreator might be better, since it comes from the Qt project.

( This bug report explains that the version 3.0.1 of QtCreator shipped with Ubuntu 14.04 will give the error message:

Project ERROR: You need to set the ANDROID_NDK_ROOT environment variable

so I downloaded a later version of QtCreator 3.1.0.  You can’t just use >sudo apt-get install qtcreator.

In my experience, Ubuntu lags behind on Qt, and Qt changes rapidly, so it is worthwhile to download the latest Qt.)

At this website I chose the ‘Qt Online Installer’, and the file ‘qt-opensource-linux-x86-1.6.0-4-online’ was downloaded.  Then give it execute permission and click on the downloaded file.  The ‘Qt Setup Wizard’ app opens.  Accept the defaults, and newer versions of Qt and Qt Creator will be downloaded to ~/Qt directory.  (This will include the Qt library built for ARM i.e. for Android.)

(As explained by the Qt project, Qt is supports iOS, but QtCreator doesn’t support iOS directly, you will need to use a .pro file AND the Apple Xcode IDE for that.  This blog may apply to using OSX as the host and cross compiling to Android.)

Install more tool chain

Qt Creator (when cross compiling for Android) relies on:

  • Android SDK
  • Android NDK
  • ant
  • JDK

Installing Android SDK

Navigate your browser to the Android SDK download website.

Under ‘SDK Tools Only‘, choose a package to download.  (I don’t want a package that includes the Eclipse IDE or the newer ‘Android Studio’ IDE, since I am using the QtCreator IDE.)

Extract the package, say to your home directory.

Refreshing the Android SDK

Now you have just the basics, as explained here by the Android team.  You use the ‘Android SDK Manager’ to download more.  It is a package manager.  You can start it from a command line:

>cd ~/android*/tools
>./android sdk

A GUI app will open.  It lets you browse a tree directory of packages to install.  It will open with an appropriate set (the latest) packages you need to download.  That includes:

  • Android SDK Platform-tools
  • Android SDK Build-tools
  • a version of the Android API

I unselected the latest version of the Android API (Android L, API 20 preview) and selected the next API (since I don’t want to mess with a possibly unstable API.)

Now choose the ‘Install packages ‘button.

Downloading the Android NDK

The SDK is for developing in Java.  You need the NDK for developing in C.

Navigate your browser to the Android Developer website page for downloading the NDK.  Choose the download for your host word length (32-bit or 64-bit) (in my case, 32-bit Ubuntu 14.04) and for your target Android word length (in my case, 32-bit, since I am just testing and have no specific target device in mind.)

Extract the download, say to your home directory.

Installing Ant

(I’m not sure what kind of tool ant is.)

>sudo apt-get install ant

Install a JDK

You can use the Ubuntu Software Center to find the name of the package and download it.  Search for ‘JDK’ and also choose ‘Show xxx technical items’ near the bottom.  I chose openjdk-7-jdk, but clicking the ‘Install’ button didn’t seem to work, so…

>sudo apt-get install openjdk-7-jdk

Configure QtCreator to use the tool chain: SDK, NDK, ant, and JDK

Start QtCreator and choose Tools>Options>Android.  Click the ‘Browse’ buttons and navigate to the location where you downloaded the tools.  (For many of them, Qt Creator leads you to the right place, but for the JDK I had to navigate to /usr/lib/jvm/java-7-openjdk-i386.

Configure QtCreator to use the Android kit

Choose Tools>Options>Build&Run.  Choose ‘Android for armeabi-v7a (GCC 4.8, Qt 5.3.1)’, which is auto-detected.

Create an example Project

I followed this tutorial.  I don’t really want to use QtQuick, but this is just an example.

(I also took shortcuts with the example.  Instead of displaying an SVG file and moving it, I just displayed the white rect that appears in the default QML.)

After creating the project, I clicked on the ‘Run’ icon. Now it says that I do not have an Android device.  It offered to create one for me (a ‘Create Android Virtual Device’ button.)  I clicked on that, entered a name for the device, and clicked OK.  Then I got an error: ‘Error: invalid –tag default …’  (I suppose it is a bug in QtCreator that might be finessed by different choices.)  But I decided to use Android tools to create an AVD….

Create an AVD using the Android AVD Manager tool

An AVD is a simulator, or Android virtual device.  The Android project provides a tool ‘Android Virtual Device Manager’ for creating them.

>cd ~/android*/tools
>./android avd

A GUI app will open.  Create an AVD.  (Glossing the details, but the defaults usually work, and for a clean development machine, you will only see the choices from the things you installed earlier.)

I suppose the list of AVD’s is in a standard place that QtCreator knows about.

Testing

Now in QtCreator when I click the Run button, it:

  • lets me chose the AVD I just created
  • proceeds to build,
  • starts the AVD
  • downloads my app to the AVD

It takes a while for the AVD to boot itself.  For a while you may see a black screen or a green arc going in circles.  I don’t think the app can load while it is booting.  (When it finishes booting, you can interact with the AVD like a real phone, using the mouse.   It seems to start in Android’s ‘Getting Started’ help screens (several screens telling you that a swipe does) just as if you had just powered up a newly purchased and activated phone.)

I suppose QtCreator timed out waiting for the AVD to boot.  I got:

Unable to start 'org.qtproject.example.accelbubble'.

But the AVD kept running.  I tried the Run button again.  This time, the application seemed to start on the AVD: it displayed a white rectangle.  I tried to click with the mouse in the app to close it, that didn’t work.  A swipe with the mouse (pressing the LMB while moving) killed the app in the AVD.

 

 

 

Advertisements

3 thoughts on “Using QtCreator on Linux to cross compile for Android

  1. Pingback: Using pyqtdeploy0.5 on Linux to cross compile a PyQt app for Android | plashless

  2. Pingback: Deploying PyQt Python Qt apps cross platform using pyqtdeploy | plashless

  3. Pingback: Using QtCreator on host OSX to cross compile for target Android | plashless

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s