On Android, applications are distributed in specially structured types of ZIP packages called Application Packages (APK) or Android App Bundles (AAB). APK files can be downloaded to and executed on a device, whereas AAB is intended to be interpreted by the Google Play store and is used to generate APK files.
Qt for Android has binaries for armv7a, arm64-v8a, x86, and x86-64. To support several different ABIs in your application, build an AAB that contains binaries for each of the ABIs. The Google Play store uses the AAB to generate optimized APK packages for the devices issuing the download request and automatically signs them with your publisher key.
Qt Creator supports the following methods of deployment for Android applications:
注意: Since Qt Creator 4.12, Ministro is not supported.
To specify settings for application packages, select Projects > Build Android APK > 细节 .
For more information about options that you have for running applications, see Specifying Run Settings for Android Devices .
Because bundling applications as APK packages is not trivial, Qt 5 provides a deployment tool called
androiddeployqt
. When you deploy an application using a
Qt for Android Kit
, Qt Creator uses the
androiddeployqt
tool to create the necessary files and to bundle them into an APK:
The Gradle wrappers and scripts are bundled only if you use Gradle to build the application packages. For more information, see 连接 Android 设备 .
To view the packages that the
androiddeployqt
tool created, select the
Open package location after build
check box.
The packages are deployed on the connected Android devices. To switch the device used as a default device for the selected kit, select Projects > 运行 > Deploy to Android Device > Reset Default Devices . The setting applies until you restart Qt Creator. For more information, see Selecting Android Devices .
更多信息有关
androiddeployqt
tool, see
在 Android 部署应用程序
.
You can specify settings for the
androiddeployqt
tool in Qt Creator and in the project .pro file. To specify settings in Qt Creator, select
Projects
>
构建
>
Build Android APK
>
细节
.
The anddroiddeployqt tool uses the information in the project .pro file to create APKs. For more information about the qmake variables that you can set in the .pro file to tailor the APK, see 在 Android 部署应用程序 .
You can view information about what the anddroiddeployqt tool is doing in the Compile Output pane. To view additional information, select the Verbose output check box.
在 Android build SDK field, you can select the API level to use for building the application. Usually, you should select the newest API level available.
注意: For Qt 5.12.0 to 5.12.5 and Qt 5.13.0 to 5.13.1, Android build SDK 28 should be used. For recent versions than the latter, build SDK 29, or the most recent should be used.
This field does not specify the minimum supported API level nor the target API level, which you can specify in the Android manifest. See Editing Manifest Files . For more information about Android API levels, see What is API Level? .
For testing the application locally, use the APK format, because the package can be uploaded directly to the device and run. For distribution to the Google Play store, create an AAB by selecting the Build .aab (Android App Bundle) check box.
When building with CMake, you can view the selected ABIs in the Initial CMake parameters field in the CMake section. You can set additional ABIs as values of the ANDROID_ABI key:
When building with qmake, you can select the ABIs in the ABIs field in the Build Steps :
To publish your application, you must sign it by using a public-private key pair that consists of a certificate and a corresponding private key and is identified by an alias . The key pair is used to verify that the future versions of your application are actually created by you.
警告: Keep the key pair in a safe place and take back up copies, because you cannot update the application if you lose the key pair.
You can use Qt Creator to generate a keystore and a self-signed certificate. The generated certificate has the structure of an X.509 v3 digital certificate. It contains information about the version, serial number, and validity period of the certificate, the ID of the algorithm that is used to encrypt the data, the organization that issued the certificate, and the subject (owner) of the certificate. In case of a self-signed certificate, the issuer and owner of the certificate are the same. In addition, the certificate contains information about the algorithm that is used to sign the certificate, as well as the signature of the certificate.
The keystore is protected by a password. In addition, you can protect each alias with its individual password.
When you sign an Android application, you must select a keystore that contains certificates and a certificate alias from the keystore. The public key (certificate) for the alias is embedded into the APK during signing.
To create a keystore and a self-signed certificate:
To sign an Android package by using a key pair, set the Sign package group settings described in Specifying Settings for Packages :
Qt Creator automatically detects which Qt libraries the application uses and adds them as dependencies. If the application needs external libraries, specify them in Projects > 构建 > Build Android APK > 额外库 field. The libraries are copied into your application's library folder and loaded on startup.
To add OpenSSL libraries, select Include prebuilt OpenSSL libraries 在 额外库 group. This will add the OpenSSL include project defined in device settings in Android OpenSSL group. This can be used for QMake and CMake projects.
Otherwise, you can manually add the paths to the required
libssl.so
and
libcrypto.so
libraries to the
额外库
field.
You can use the qmake variables to specify all the settings you need for the
androiddeployqt
tool and you do not need an Android manifest file unless you need to specify Android specific settings like the application's icon. Also, the manifest file is needed if you want to publish the package in the Play Store.
Android application packages are usually named by using a hierarchical pattern with the levels in the hierarchy separated by periods (.). In general, a package name begins with the top level domain name of the organization followed by the organization's domain name and any subdomain names listed in reverse order. The organization can then choose a specific name for their package. Package names should be written in all lowercase characters whenever possible. For example,
org.qtproject.example
.
Complete conventions for disambiguating package names and rules for naming packages when the Internet domain name cannot be directly used as a package name are described in section 7.7 of the Java Language Specification.
For more information about package names, see Android Application Fundamentals .
Qt uses different methods to determine how Qt Widgets and Qt Quick Controls should be styled:
注意: This method uses some Android non-SDK interfaces, that are being restricted by Google starting from Android 9.0 (API 28).
You can specify different options for determining screen orientation, depending on sensor readings or user preferences. The following table lists the options available.
| Orientation | 描述 |
|---|---|
| Unspecified | The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device. |
| Behind | Use the same orientation as the activity that's immediately beneath it in the activity stack. |
| Landscape | Landscape orientation, where the display width is larger than its height. |
| Portrait | Portrait orientation, where the display height is larger than its width. |
| Reverse landscape | Landscape orientation in the opposite direction of normal landscape. |
| Reverse portrait | Portrait orientation in the opposite direction of normal portrait. |
| Sensor landscape | Landscape orientation, but it can be either normal or reverse landscape based on the device sensor. The sensor is used even if the user has locked sensor-based rotation. |
| Sensor portrait | Portrait orientation, but it can be either normal or reverse portrait based on the device sensor. The sensor is used even if the user has locked sensor-based rotation. |
| User landscape | Landscape orientation, but it can be either normal or reverse landscape based on the device sensor and the user's preference. |
| User portrait | Portrait orientation, but it can be either normal or reverse portrait based on the device sensor and the user's preference. |
| Sensor | The orientation is determined by the device orientation sensor. The orientation of the display depends on how the user is holding the device. It changes when the user rotates the device. Some devices, however, will not rotate to all four possible orientations by default. To allow all four orientations, select the full sensor option. The sensor is used even if the user locked sensor-based rotation. |
| Full sensor | The orientation is determined by the device orientation sensor for any of the four orientations. This is similar to the sensor option, except that it allows any of the four possible screen orientations, regardless of what the device will normally do. For example, some devices won't normally use reverse portrait or reverse landscape, but this option enables them. |
| No sensor | The orientation is determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. |
| User | The user's current preferred orientation. |
| Full user | If the user has locked sensor-based rotation, this option behaves in the same way as the user option. Otherwise, it behaves the same as the full sensor option, and allows any of the four possible screen orientations. |
| Locked | Locks the orientation to its current rotation, whatever that is. |
You can set different images to be shown as application icons and splash screens on low, medium, high, and extra high DPI displays. The following list summarizes the DPI values typically associated with each category:
If you use qmake as the build system, you can create an Android manifest file and edit it in Qt Creator.
To create an Android manifest file and to open it in the Android Manifest Editor:
org.example.myapplication
. The application is launched by an automatically generated Java launcher that is packaged with the application into an Android package (.apk).
androiddeployqt
tool by default is 14, which means that the overflow button in the system navigation bar will not be enabled by default.
android.permission.WRITE_EXTERNAL_STORAGE
for
Qt Core
or
android.permission.ACCESS_COARSE_LOCATION
for
Qt Location
.
On the top header, select the XML Source tab to edit the file in XML format.