- Qt 5.3
- Platform and Compiler Notes - Android
- Qt 5.3.2 Reference Documentation

# Platform and Compiler Notes - Android

This page contains information particular to building Qt applications for and running them on the Android platform. Qt supports Android versions 2.3.3 (API level 10) or later.

## Android Development in Qt Creator

The easiest way to develop with Qt for Android is to use Qt Creator. When you apply a Qt for Android Kit to a Qt Creator project, it will create and maintain a set of files which are required to make your application run on Android.

The files added to your project are:

- .java files will serve as the entry point into your application and automatically load Qt to execute the native code in your application
- AndroidManifest.xml which provides meta-information about your application
- Other XML files detailing the dependencies of your application
- Resource files
- Depending on the deployment method selected in Qt Creator, additional files like libraries and QML files can be included in the project.

Qt Creator adds these files in a subdirectory of your project called android. The contents of the android folder is used as basis for your app's distributable application package.

## Application Package

On Android, apps are distributed in packages called APK. Qt Creator builds the APK for you, but if you for some reason want to do this manually, you must first make sure that the appropriate packaging and build files are in place. For more detailed information about how the packaging is done, see Deploying an Application on Android.

## Deployment

Qt Creator currently supports three methods of deployment for Android apps: the default deployment method is suitable for distribution of the APK file. With this deployment method, the necessary Qt libraries and files will be copied into your project directory, and bundled as part of the APK, so that you get a stand-alone, distributable application package.

### Deployment with Ministro

The second method is suitable if you want to minimize the size of your APK, and can be selected by opening the Run settings of your project, expanding Deploy Configurations and removing the tick from the Use local Qt libraries check box. In this case, your application will have an external dependency called Ministro. If a user downloads your application, and it is the first application on their device to depend on Ministro, they will be asked to install it before they can run your application. Ministro downloads Qt libraries from a repository of your choice. The repository URL can be set by editing the file android/res/values/libs.xml which is created by Qt Creator when configuring your project. Ministro will then serve as a central repository for Qt libraries, and several apps can share the libraries to limit the amount of duplication. Note that using this deployment method requires a repository for the libraries you want to distribute.

### Deployment for Debugging

The third method is more convenient when you are simply testing your application on a device physically connected to your development machine (or an emulator). It will copy the Qt libraries into a temporary directory on your device and run the application against these instead. An APK built in this way is not distributable, since it relies on the device being prepared to contain the Qt libraries in the correct location. However, since the Qt libraries are only copied into the device once, it benefits from a faster turn-around time, so it's more suited for testing changes to your application during development. This deployment method can be selected by opening the Run settings of your project, expanding Deploy Configurations and choosing Deploy local Qt libraries. Make sure the Use local Qt libraries check box is also ticked.

## Plugins and Imports Special Considerations

If an application uses plugins or imports that depend on other modules, these modules have to be listed in the application's dependencies. This is because Qt Creator does not know ahead of time which imports or plugins your application will end up loading.

For example, if your application's QML code imports Qt Multimedia, then the Qt Multimedia module must explicitly be made a dependency of the application. You can do this by adding it to the application .pro file:

    QT += multimedia

It is also possible to manually enable dependencies on Qt libraries by opening the Run settings of your project, expanding Package configurations and selecting the Libraries tab. Manually check the libraries that are dependencies of your project.

## Text Special Considerations

Because of a bug in some OpenGL drivers, the mechanism used by Qt to cache text glyphs does not work as expected on all Android devices, causing text to appear scrambled. To remedy this, a workaround is in place, which increases memory consumption and can also affect text rendering performance. Before Qt 5.3.2, the workaround was enabled only for a particular set of devices. It is now used by default on all devices.

You can disable the workaround by setting the `QT_ANDROID_DISABLE_GLYPH_CACHE_WORKAROUND` environment variable to `1`. You should do so only after verifying that text appears correctly on all targeted devices.

## OpenGL Special Considerations

Qt for Android provides two separate platform plugins: One which is suited for traditional widget-based apps that do not require OpenGL support, and one which will be used when OpenGL is required. When building and deploying your app, Qt Creator will detect whether the OpenGL-enabled plugin is required by checking if your app depends on either the Qt OpenGL module or the Qt Quick module.

There are some special considerations to be made when the OpenGL-enabled platform plugin is in use. The plugin only supports full screen top-level windows. This means that even dialogs and popups will be shown as full screen. There may also be drawing errors if you try to stack windows that have animations or otherwise require updating their UI while they are obscured by another window.

It is recommended that you try to avoid multiple top-level windows in the case of Android apps, as there is no traditional window system on this platform.

Note: Embedding a QGLWidget inside a widget hierarchy is not supported. When QGLWidget is in use, it must be the top-level widget.

## Multimedia Special Considerations

Qt Multimedia, like the rest of Qt, supports Android versions 2.3.3 (API level 10) or later. There is however an exception for video output which requires Android versions 3.0 (API level 11) or later. This affects camera preview and video player features.

Additionally, the Qt Multimedia Widgets module is not supported on Android, which means video display is only available using the VideoOutput and Video QML items.

## Assets File System

Qt for Android provides a special, virtual file system which is based on the assets mechanism in Android. Files that are put under assets in the android folder created by Qt Creator, will be packaged as part of your application package. These can be accessed in Qt by prefixing the paths with `assets:/`. For instance, to access the image logo.png in the folder assets/images, you can use `QPixmap("assets:/images/logo.png")`.

If using the assets mechanism is not required for your app, the recommended way of distributing resources with your Qt app is to use the Qt Resource System, which is a cross-platform mechanism for distributing resources with your app.

## Supported Architectures

Qt for Android currently has binaries for ARMv7 and x86. Make sure you select the correct architecture for the device or emulator you are targeting, otherwise your application will crash. The MIPS archictecture is currently not supported by Qt.

If you want to support several different architectures in your application, the recommendation is to build separate APKs for each architecture, so that each APK only contains the binaries required for the targeted architecture. For more information about this, see the Android documentation about Multiple APK Support.