/usr/share/qt5/doc/qtdoc/deployment-android.html is in qt5-doc-html 5.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- deployment.qdoc -->
<title>Deploying an Application on Android | QtDoc 5.2</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li><a href="index.html">Qt 5.2</a></li>
<li>Deploying an Application on Android</li>
<li id="buildversion">
Qt 5.2.1 Reference Documentation</li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<p class="naviNextPrevious headerNavi">
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#the-apk-package">The APK package</a></li>
<li class="level1"><a href="#package-template">Package template</a></li>
<li class="level2"><a href="#androidmanifest-xml">AndroidManifest.xml</a></li>
<li class="level2"><a href="#java-code">Java code</a></li>
<li class="level2"><a href="#resources">Resources</a></li>
<li class="level3"><a href="#res-values-libs-xml">res/values/libs.xml</a></li>
<li class="level3"><a href="#res-values-strings-xml">res/values/strings.xml</a></li>
<li class="level2"><a href="#libraries">Libraries</a></li>
<li class="level1"><a href="#building-the-android-application-package">Building the Android application package</a></li>
<li class="level1"><a href="#androiddeployqt">androiddeployqt</a></li>
<li class="level2"><a href="#required-steps-before-running-androiddeployqt">Required steps before running androiddeployqt</a></li>
<li class="level2"><a href="#command-line-arguments">Command line arguments</a></li>
<li class="level1"><a href="#dependencies-detection">Dependencies detection</a></li>
<li class="level1"><a href="#qmake-variables">qmake variables</a></li>
<li class="level1"><a href="#qt-creator">Qt Creator</a></li>
</ul>
</div>
<h1 class="title">Deploying an Application on Android</h1>
<span class="subtitle"></span>
<!-- $$$deployment-android.html-description -->
<div class="descr"> <a name="details"></a>
<p>This article gives a technical description of the steps required to take any given Qt application and deploy it to an Android device (or market place).</p>
<p>It is recommended that you use the <a href="#androiddeployqt">androiddeployqt deployment tool</a> or Qt Creator to automate this work rather than perform the steps manually. The following information will give you a technical insight into the structure of the resulting Android application which is not normally required just to write an application.</p>
<a name="the-apk-package"></a>
<h2>The APK package</h2>
<p>Applications on Android are packaged in a specially structured type of ZIP file called <tt>APK</tt>. When you build a Qt application using <tt>qmake</tt> and <tt>make</tt>, the result will be a binary file which is built with the correct compiler and flags to be usable on an Android device with the target architecture.</p>
<p>In order to turn this into a runnable application, it has to be put into a special directory structure with some other files and packaged into an APK package.</p>
<a name="package-template"></a>
<h2>Package template</h2>
<p>A template for the other sources of an APK package is contained in <tt>$QTDIR/src/android/java</tt>. The first step of making an APK is to copy these files into an empty directory. In this guide, we'll refer to this build directory as <tt>$BUILD_TARGET</tt>.</p>
<p>We also need to make sure the application binary is copied into the package. This can be achieved by using the following command after running qmake on your application's project file:</p>
<pre class="cpp">make install INSTALL_ROOT<span class="operator">=</span>$BUILD_TARGET</pre>
<p>It will copy the application binary and any other installation requirements into the packaging directory.</p>
<p>The packaging directory will now consist of the following parts:</p>
<a name="androidmanifest-xml"></a>
<h3>AndroidManifest.xml</h3>
<p>The <tt>AndroidManifest.xml</tt> file gives detailed meta-information about your application. This information is used for several things. It is used by the target device to decide which features to enable, the default orientation of the application, and so on. In addition, it's used by the market place for information on the version code, device support, package name, and lots more.</p>
<p>For more information about general capabilities of and requirements for the <tt>AndroidManifest.xml</tt> file, please refer to the <a href="http://developer.android.com/guide/topics/manifest/manifest-intro.html">Android documentation on this topic</a>.</p>
<p>There are some special variables recognized by Qt which can be placed inside the manifest:</p>
<ul>
<li><tt>android.app.use_local_qt_libs</tt>: If this is set to <tt>1</tt>, Qt libraries are expected to be found on the target device. If it is <tt>0</tt>, then libraries must be requested from the <b>Ministro</b> service.</li>
<li><tt>android.app.bundle_local_qt_libs</tt>: If set to <tt>1</tt>, the Qt libraries are expected to be bundled as part of the <tt>APK</tt>. If set to <tt>0</tt>, they are expected to be found in the <tt>/data/local/tmp/qt</tt> folder on the target device.<p><b>Note: </b>If <tt>use_local_qt_libs</tt> is 0, then this variable has no effect, since libraries are then requested through Ministro instead.</p></li>
</ul>
<p>Other variables in the manifest refer to resources, and more information about these can be found in the <a href="../qmake/qmake-variable-reference.html#resources">documentation for the resources</a> below.</p>
<a name="java-code"></a>
<h3>Java code</h3>
<p>Under <tt>$BUILD_TARGET/src</tt> are the files comprising the Java code of the Android application. The regular Android application launcher is a Java process, so Qt applications have a Java-based entry point. The code in here will load the required Qt libraries, based on the meta-information given in other files in the template. The code supports all the three deployment mechanisms which are supported in Qt Creator and <tt>androiddeployqt</tt>: <i>Bundled</i>, <i>Ministro</i> and <i>Debug</i>.</p>
<p>After loading the libraries, the Java code will call into the application's native <tt>main()</tt> function on a new thread and the application will launch. At this point, the Java code in the template is used to delegate events from Android into Qt.</p>
<p>One thing to note about the files in this directory is that they can contain code specific to certain Android versions. Based on the minimum required Android API level of your application it might be necessary to remove some of this code. This is done automatically by <tt>androiddeployqt</tt> and Qt Creator during packaging.</p>
<p>For example, lets say the code contains the following:</p>
<pre class="cpp"><span class="comment">//@ANDROID-12</span>
@Override
<span class="keyword">public</span> boolean dispatchGenericMotionEvent(MotionEvent ev)
{
<span class="keyword">if</span> (<span class="type">QtApplication</span><span class="operator">.</span>m_delegateObject <span class="operator">!</span><span class="operator">=</span> null <span class="operator">&</span><span class="operator">&</span> <span class="type">QtApplication</span><span class="operator">.</span>dispatchGenericMotionEvent <span class="operator">!</span><span class="operator">=</span> null)
<span class="keyword">return</span> (Boolean) <span class="type">QtApplication</span><span class="operator">.</span>invokeDelegateMethod(<span class="type">QtApplication</span><span class="operator">.</span>dispatchGenericMotionEvent<span class="operator">,</span> ev);
<span class="keyword">else</span>
<span class="keyword">return</span> super<span class="operator">.</span>dispatchGenericMotionEvent(ev);
}
<span class="comment">//@ANDROID-12</span></pre>
<p>If your minimum Android API level is 11 or lower, then the code should be removed before building, since it's not a supported API on Android API level 11. However, if your minimum API level is 12 or higher, it should be left in.</p>
<a name="resources"></a>
<h3>Resources</h3>
<p>Under the <tt>res/</tt> folder in the <tt>$BUILD_TARGET</tt> are Android resources that can be accessed from the <tt>AndroidManifest.xml</tt> and Java code of your application. A typical example of resources which should be placed here are the icon files used by the application launcher to represent your application.</p>
<p>In Qt, some translations used for the Ministro service and some files with meta-information are in the default resources of the application.</p>
<a name="res-values-libs-xml"></a>
<h4>res/values/libs.xml</h4>
<p>One of the files containing meta information about the deployment of the application is <tt>libs.xml</tt>. It consists of the following values:</p>
<ul>
<li><tt>qt_sources</tt>: The URL of one or more Ministro repositories that contain the necessary Qt libraries. This is used when the Ministro deployment mechanism is active. Read the <a href="http://necessitas.kde.org/necessitas/ministro.php">Ministro documentation</a> for more information about such repositories.</li>
<li><tt>repository</tt>: The Ministro repository to use at the given URL. This is used when the Ministro deployment mechanism is active.</li>
<li><tt>bundled_libs</tt>: Libraries in the APK's library folder which should be loaded on start-up. Library names should be specified without the <tt>lib</tt> prefix and <tt>.so</tt> suffix.</li>
<li><tt>qt_libs</tt>: Qt libraries which should be loaded on start-up. When bundled deployment is used, these are expected to be found inside the <tt>APK</tt>'s library folder. When Ministro deployment is in use, they are requested from the Ministro service on the device. And when debugging deployment is in use, they are loaded from the <tt>/data/local/tmp/qt</tt> directory on the target device.</li>
<li><tt>bundled_in_lib</tt>: List of plugins which are bundled in the <tt>APK</tt>'s library folder. This is only used when the bundling deployment mechanism is active. Qt's plugin system requires plugins to be placed in a special directory structure which contains information about the plugin category. The library folder in the APK does not support such a directory structure, so the bundled_in_lib array contains the information lost when the directory structure is flattened. Each item is a pair of paths, separated by a colon. The first of the pair is the file name of the file bundled inside the <tt>APK</tt>'s library folder. The second of the pair is the original path of the file, relative to the Qt installation.</li>
<li><tt>bundled_in_assets</tt>: List of other types of Qt files which are bundled inside the <tt>APK</tt>'s asset folder. This value is only used when the bundling deployment mechanism is active. The format of the items is the same as for the <tt>bundled_in_lib array</tt>. The difference is that the first of the pairs refers to the path of a file inside the <tt>assets</tt> directory of the application instead of the library directory. This array is typically used for bundling QML imports, which also require a special directory structure to be used inside Qt.</li>
</ul>
<a name="res-values-strings-xml"></a>
<h4>res/values/strings.xml</h4>
<p>The <tt>strings.xml</tt> file contains some strings used by the <tt>AndroidManifest.xml</tt> and by the deployment mechanisms, as well as some strings used when loading the Ministro service.</p>
<p>In particular, the application name and the name of the application binary can be specified here. There are also strings that contain additional libraries that should be loaded and <tt>JAR</tt> files which should be included in the class path. The latter is only used for deployment with Ministro or debug deployment.</p>
<a name="libraries"></a>
<h3>Libraries</h3>
<p>Under <tt>libs</tt> in the package directory, it's possible to place libraries that should be included in the application bundle. <tt>JAR</tt> libraries should be placed directly under <tt>libs/</tt>, while shared libraries should be put in a subdirectory suitably named after the target architecture of the libraries.</p>
<p>For deployment that bundles Qt in the <tt>APK</tt>, the Qt <tt>JAR</tt> files that are suffixed with <tt>"bundled"</tt> should be put into the libs directory. It is also required that the necessary shared libraries and plugins are placed in the appropriate subdirectory of libs.</p>
<a name="building-the-android-application-package"></a>
<h2>Building the Android application package</h2>
<p>Once all the pieces are in place, a few steps are required to build the application package. First, a build script needs to be generated. This is done using the <tt>android</tt> tool which is part of the Google Android SDK.</p>
<p>Example:</p>
<pre class="cpp"> <span class="operator">%</span> android update project <span class="operator">-</span><span class="operator">-</span>path $BUILD_TARGET <span class="operator">-</span><span class="operator">-</span>target android<span class="operator">-</span><span class="number">9</span> <span class="operator">-</span><span class="operator">-</span>name <span class="type">QtApp</span></pre>
<p>This example will create build files in <tt>$BUILD_TARGET</tt> for an <tt>APK</tt> named <tt>QtApp</tt>. The Java code will be compiled against the <tt>android-9</tt> platform.</p>
<p>The project can then be built using the ant tool. If a release package is built it can be signed and aligned using <tt>jarsigner</tt> and <tt>zipalign</tt>.</p>
<a name="androiddeployqt"></a>
<h2>androiddeployqt</h2>
<p>Building an application package is complex, so Qt comes with a tool which handles the work for you. The steps described in this document so far are handled automatically by the tool.</p>
<a name="required-steps-before-running-androiddeployqt"></a>
<h3>Required steps before running androiddeployqt</h3>
<p>Before running the tool, you need run <tt>qmake</tt> and <tt>make</tt> your project. Running <tt>qmake</tt> creates the <tt>Makefile</tt>, and it will also generate a <tt>JSON</tt> file containing important settings used by <tt>androiddeployqt</tt>.</p>
<p>You should then install the application binary (and any other requirements) into the library folder of the <tt>APK</tt>. If <tt>$BUILD_TARGET</tt> is your build directory (the first time you do this, the directory should be empty at this point), then you can install the binary with the following command:</p>
<pre class="cpp"> <span class="operator">%</span> make install INSTALL_ROOT<span class="operator">=</span>$BUILD_TARGET</pre>
<a name="command-line-arguments"></a>
<h3>Command line arguments</h3>
<p>The only required command line argument when running the tool is <tt>--output</tt>. This should be set to <tt>$BUILD_TARGET</tt>, that is: the build directory where you installed your application binary.</p>
<p>Other command line arguments are optional but useful. Here's a quick overview. More information is available by passing the <tt>--help</tt> argument to androiddeployqt.</p>
<ul>
<li><tt>--input <file name></tt>: This allows you to specify the <tt>JSON</tt> file generated by <tt>qmake</tt>. By default, <tt>androiddeployqt</tt> will try to guess the file name based on the current working directory.</li>
<li><tt>--deployment <mechanism></tt>: Specify this to pick a different deployment mechanism than the default.</li>
<li><tt>--install</tt>: Specify this to install the finished package on the target device or emulator. Note that if a previous version of the package is already installed, it will be uninstalled first, removing any data it might have stored locally.</li>
<li><tt>--device <ID></tt>: Specify the ID of the target device or emulator as reported by the <tt>adb</tt> tool. If an ID is specified, it will be passed to all calls to <tt>adb</tt>. If it is unspecified, no particular device or emulator will be requested by <tt>adb</tt>, causing it to pick a default instead.</li>
<li><tt>--android-platform <platform></tt>: The SDK platform used for building the Java code of the application. By default, the latest available platform is used.</li>
<li><tt>--ant <path></tt>: Specify the path to the <tt>ant</tt> executable. If this is unspecified, <tt>androiddeployqt</tt> will attempt to detect it on the <tt>PATH</tt>.</li>
<li><tt>--release</tt>: Specify this to create a release package instead of a debug package. With no other arguments, release packages are unsigned and cannot be installed to any device before they have been signed by a private key.</li>
<li><tt>--sign <url> <alias></tt>: Sign the resulting package. Specifying this also implies <tt>--release</tt>. The URL of the keystore file and the alias of the key have to be specified. In addition, there are a number of options that can be specified which are passed through to the <tt>jarsigner</tt> tool. Pass <tt>--help</tt> to <tt>androiddeployqt</tt> for more information about these.</li>
<li><tt>--jdk <path></tt>: Specify the path to the Java Development Kit. This is only required for signing packages, as it is only used for finding the <tt>jarsigner</tt> tool. If it is unspecified, then <tt>androiddeployqt</tt> will attempt to detect <tt>jarsigner</tt>, either using the <tt>JAVA_HOME</tt> environment variable, or on the <tt>PATH</tt>.</li>
<li><tt>--verbose</tt>: Specify this to output more information about what <tt>androiddeployqt</tt> is doing.</li>
</ul>
<a name="dependencies-detection"></a>
<h2>Dependencies detection</h2>
<p>Qt comes with a number of plugins which are loaded at run-time when they are needed. These can handle anything from connecting to SQL databases to loading specific image formats. Detecting plugin dependencies is impossible as the plugins are loaded at run-time, but androiddeployqt tries to guess such dependencies based on the Qt dependencies of your application. If the plugin has any Qt dependencies which are not also dependencies of your application, it will not be included by default. For instance, in order to ensure that the SVG image format plugin is included, you will need to add <tt>QT += svg</tt> to your <tt>.pro</tt> file so that the <a href="../qtsvg/qtsvg-index.html">Qt SVG</a> module becomes a dependency of your application.</p>
<p>If you are wondering why a particular plugin is not included automatically, you can run androiddeployqt with the <tt>--verbose</tt> option to get the list of missing dependencies for each excluded plugin. You can achieve the same in Qt Creator by ticking the <b>Verbose output</b> check box in the <b>Deployment configurations</b>. This is located in the <b>Run</b> tab of your <b>Projects</b> settings.</p>
<p>It's also possible to manually specify the dependencies of your application. See the documentation for the <tt>ANDROID_DEPLOYMENT_DEPENDENCIES</tt> qmake variable below.</p>
<a name="qmake-variables"></a>
<h2>qmake variables</h2>
<p>Unless the project has special requirements such as third party libraries, it should be possible to run <tt>androiddeployqt</tt> on it with no modifications and get a working Qt for Android application as a result.</p>
<p>However, there are a set of <tt>qmake</tt> variables that can be used to tailor your package. At some point during development, you will most likely want to look into these variables, as they will e.g. allow you to set the name of your application as it appears in the application menu on devices.</p>
<p>Here is a list of some variables that are particularly interesting when making Android applications:</p>
<ul>
<li><tt>ANDROID_DEPLOYMENT_DEPENDENCIES</tt>: By default, <tt>androiddeployqt</tt> will detect the dependencies of your application. But since run-time usage of plugins cannot be detected, there could be false positives, as your application will depend on any plugins that are <i>potential</i> dependencies. If you want to minimize the size of your <tt>APK</tt>, it's possible to override the automatic detection using the <tt>ANDROID_DEPLOYMENT_DEPENDENCIES</tt> variable. This should contain a list of all Qt files which need to be included, with paths relative to the Qt install root. Note that only the Qt files specified here will be included. Failing to include the correct files can result in crashes.</li>
<li><tt>ANDROID_PACKAGE_SOURCE_DIR</tt>: This variable can be used to specify a directory where additions and modifications can be made to the default Android package template. The <tt>androiddeployqt</tt> tool will copy the application template from Qt into the build directory, and then it will copy the contents of the <tt>ANDROID_PACKAGE_SOURCE_DIR</tt> on top of this, overwriting any existing files. The update step where parts of the source files are modified automatically to reflect your other settings is then run on the resulting merged package. If you, for instance, want to make a custom <tt>AndroidManifest.xml</tt> for your application, then place this directly into the folder specified in this variable. You can also add custom Java files in <tt>ANDROID_PACKAGE_SOURCE_DIR/src</tt>.<p><b>Note: </b>When adding custom versions of the build files (like strings.xml, libs.xml, AndroidManifest.xml, etc.) to your project, make sure you copy them from the package template, which is located in <tt>$QT/src/android/java</tt>. You should never copy any files from the build directory, as these files have been altered to match the current build settings.</p></li>
<li><tt>ANDROID_EXTRA_LIBS</tt>: A list of external libraries that will be copied into your application's library folder and loaded on start-up. This can be used, for instance, to enable OpenSSL in your application. Simply set the paths to the required <tt>libssl.so</tt> and <tt>libcrypto.so</tt> libraries here and OpenSSL should be enabled automatically.</li>
</ul>
<a name="qt-creator"></a>
<h2>Qt Creator</h2>
<p>Qt Creator will run the <tt>androiddeployqt</tt> tool for you, and provides easy and intuitive user interfaces to specify many of the options. For more information, see <a href="http://qt-project.org/doc/qtcreator/creator-deploying-android.html">the Qt Creator documentation</a>.</p>
</div>
<!-- @@@deployment-android.html -->
<p class="naviNextPrevious footerNavi">
</p>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2013 Digia Plc and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|