Das Werkzeug androiddeployqt
Die Erstellung eines Android-Pakets umfasst viele Schritte, weshalb Qt mit einem Werkzeug geliefert wird, das diese Arbeit für Sie erledigt. Die Schritte, die das androiddeployqt-Tool durchführt, sind in Bereitstellen einer Anwendung unter Android beschrieben.
Voraussetzungen vor der Ausführung von androiddeployqt
Bevor Sie das Tool manuell ausführen, müssen Sie Ihr Projekt mit CMake
oder qmake
konfigurieren, um Makefiles
und eine JSON
Datei (d.h. android-<target_name>-deployment-settings.json
) zu erzeugen, die wichtige Einstellungen enthält, die von androiddeployqt
verwendet werden.
Hinweis: Es wird nicht empfohlen, die JSON-Datei von androiddeployqt zu ändern.
Um die Umgebung für androiddeployqt vorzubereiten, konfigurieren Sie Ihr Projekt in einem anderen Verzeichnis als Ihr Quellverzeichnis. Weitere Informationen zum Konfigurieren Ihres Projekts finden Sie unter Erstellen von Qt für Android-Projekten von der Kommandozeile aus.
Kommandozeilen-Argumente
Die einzigen erforderlichen Kommandozeilenargumente beim Ausführen des Tools sind --input
und --output
. Andere Befehlszeilenargumente sind optional, aber nützlich. Die folgende Liste ist verfügbar, wenn das Argument --help
an androiddeployqt übergeben wird.
Syntax: androiddeployqt --output <destination> [options] Creates an Android package in the build directory <destination> and builds it into an .apk file. Optional arguments: --input <inputfile>: Reads <inputfile> for options generated by qmake. A default file name based on the current working directory will be used if nothing else is specified. --deployment <mechanism>: Supported deployment mechanisms: bundled (default): Includes Qt files in stand-alone package. unbundled: Assumes native libraries are present on the device and does not include them in the APK. --aab: Build an Android App Bundle. --no-build: Do not build the package, it is useful to just install a package previously built. --install: Installs apk to device/emulator. By default this step is not taken. If the application has previously been installed on the device, it will be uninstalled first. --reinstall: Installs apk to device/emulator. By default this step is not taken. If the application has previously been installed on the device, it will be overwritten, but its data will be left intact. --device [device ID]: Use specified device for deployment. Default is the device selected by default by adb. --android-platform <platform>: Builds against the given android platform. By default, the highest available version will be used. --release: Builds a package ready for release. By default, the package will be signed with a debug key. --sign <url/to/keystore> <alias>: Signs the package with the specified keystore, alias and store password. Optional arguments for use with signing: --storepass <password>: Keystore password. --storetype <type>: Keystore type. --keypass <password>: Password for private key (if different from keystore password.) --sigfile <file>: Name of .SF/.DSA file. --digestalg <name>: Name of digest algorithm. Default is "SHA-256". --sigalg <name>: Name of signature algorithm. Default is "SHA256withRSA". --tsa <url>: Location of the Time Stamping Authority. --tsacert <alias>: Public key certificate for TSA. --internalsf: Include the .SF file inside the signature block. --sectionsonly: Do not compute hash of entire manifest. --protected: Keystore has protected authentication path. --jarsigner: Deprecated, ignored. NOTE: To conceal the keystore information, the environment variables QT_ANDROID_KEYSTORE_PATH, and QT_ANDROID_KEYSTORE_ALIAS are used to set the values keysotore and alias respectively. Also the environment variables QT_ANDROID_KEYSTORE_STORE_PASS, and QT_ANDROID_KEYSTORE_KEY_PASS are used to set the store and key passwords respectively. This option needs only the --sign parameter. --jdk <path/to/jdk>: Used to find the jarsigner tool when used in combination with the --release argument. By default, an attempt is made to detect the tool using the JAVA_HOME and PATH environment variables, in that order. --qml-import-paths: Specify additional search paths for QML imports. --verbose: Prints out information during processing. --no-generated-assets-cache: Do not pregenerate the entry list for the assets file engine. --aux-mode: Operate in auxiliary mode. This will only copy the dependencies into the build directory and update the XML templates. The project will not be built or installed. --apk <path/where/to/copy/the/apk>: Path where to copy the built apk. --build-aar: Build an AAR package. This option skips --aab, --install, --reinstall, and --sign options if they are provided. --qml-importscanner-binary <path/to/qmlimportscanner>: Override the default qmlimportscanner binary path. By default the qmlimportscanner binary is located using the Qt directory specified in the input file. --depfile <path/to/depfile>: Output a dependency file. --builddir <path/to/build/directory>: build directory. Necessary when generating a depfile because ninja requires relative paths. --no-rcc-bundle-cleanup: skip cleaning rcc bundle directory after running androiddeployqt. This option simplifies debugging of the resource bundle content, but it should not be used when deploying a project, since it litters the "assets" directory. --copy-dependencies-only: resolve application dependencies and stop deploying process after all libraries and resources that the application depends on have been copied. --help: Displays this information.
Mit einem project_name
, um das Anwendungspaket mit androiddeployqt
zu erstellen, ohne es auf dem Gerät bereitzustellen, führen Sie Folgendes aus:
androiddeployqt --input <build_dir>/android-project_name-deployment-settings.json \ --output <build_dir>/android-build
Zum Erstellen und Bereitstellen des Pakets auf dem Gerät:
androiddeployqt --input <build_dir>/android-project_name-deployment-settings.json \ --output <build_dir>/android-build --install --device <device_serial_id>
Erkennung von Abhängigkeiten
Qt wird mit einer Reihe von Plugins geliefert, die zur Laufzeit geladen werden, wenn sie benötigt werden. Diese können von der Verbindung zu SQL-Datenbanken bis hin zum Laden bestimmter Bildformate alles mögliche erledigen. Die Erkennung von Plugin-Abhängigkeiten ist unmöglich, da die Plugins zur Laufzeit geladen werden, aber androiddeployqt versucht, solche Abhängigkeiten anhand der Qt-Abhängigkeiten Ihrer Anwendung zu erraten. Wenn das Plugin irgendwelche Qt-Abhängigkeiten hat, die nicht auch Abhängigkeiten Ihrer Anwendung sind, wird es standardmäßig nicht eingebunden. Um zum Beispiel sicherzustellen, dass das SVG-Bildformat-Plugin enthalten ist, müssen Sie das Qt SVG Modul zu Ihrem Projekt hinzufügen, damit es zu einer Abhängigkeit Ihrer Anwendung wird:
find_package(Qt6 REQUIRED COMPONENTS Svg) ... target_link_libraries(target_name PRIVATE Qt6::Svg)
Wenn Sie sich fragen, warum ein bestimmtes Plugin nicht automatisch enthalten ist, können Sie androiddeployqt mit der Option --verbose
ausführen, um die Liste der fehlenden Abhängigkeiten für jedes ausgeschlossene Plugin zu erhalten. Das Gleiche können Sie in Qt Creator erreichen, indem Sie das Kontrollkästchen Verbose output in den Bereichen Projects > Build Steps > Build Android APK > Advanced Actions aktivieren.
Es ist auch möglich, die Abhängigkeiten Ihrer Anwendung manuell zu spezifizieren. Für weitere Informationen siehe QT_ANDROID_DEPLOYMENT_DEPENDENCIES CMake-Variable.
Hinweis: androiddeployqt durchsucht die QML-Dateien des Projekts, um die QML-Importe zu sammeln. Wenn Sie jedoch QML-Code als QString von C++ zur Laufzeit laden, funktioniert dies möglicherweise nicht richtig, da androiddeployqt dies zur Bereitstellungszeit nicht erkennt. Um dies zu beheben, können Sie eine Dummy-QML-Datei hinzufügen, die solche QML-Module importiert, auf die zur Laufzeit verwiesen wird.
Bereitstellung in Qt Creator
Qt Creator verwendet androiddeployqt
unter der Haube und bietet einfache und intuitive Benutzeroberflächen zur Angabe verschiedener Optionen. Weitere Informationen finden Sie unter Qt Creator: Deploying Applications to Android Devices.
Weitere Informationen zum Anpassen und Bereitstellen einer Qt für Android-Anwendung finden Sie unter Bereitstellen einer Anwendung auf Android.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.