How to exclude unnecessary libraries from Android APK?
-
After building an Android APK of my Qt application (with the UI all in QML) and looking at the contents of that APK, I notice that it includes all the QtQuick styles that are not strictly platform specific, including the Fluent, Imagine, Basic, Universal and Fusion styles, even though being an Android app I just want the app to use the Material style and do not provide an option for the user to change that. The Fluent, Imagine, Universal and Fusion styles take up at least 8.5MB of space, which is almost 10% of the whole app's size (91.8MB for an ARMv8 release signed APK with Qt 6.10.2 plus QtSensors, QtPositioning, QtMultimedia, QtGraphs and no other external libraries), and the Basic style takes up another 1.6MB of space (although I can understand if that style is just needed as a fallback no matter what).
I did try explicitly importing
QtQuick.Controls.Materialin all my QML apps instead of justQtQuick.Controlsas well as specifyingStyle=Materialin the[Controls]section ofqtquickcontrols2.conf, which does make my app use the Material style even on desktop but those other styles still get bundled in the APK anyway.I also see some other libraries which I don't think makes sense to be included given the app's functionality, like QtVirtualKeyboard (is that required given Android has that by itself?) and some QML debugging libraries (like
libplugins_qmltooling_qmldbg_debugger_arm64-v8a.so) even though I've disabled QML debugging in the build settings, and even in release mode, although these libraries aren't as large as the styles.So, is there a way I can eliminate at least the extra styles from the APK, ideally without having to force the app to always use the Material theme even when not building for Android?
-
Hi and welcome to devnet,
From a quick look at the androiddeployqt documentation, I think you are looking for the
--copy-dependencies-onlyoption. The Dependencies Detection section might also be of interest. -
Thanks for the reply, I didn't realize that I wouldn't get any notifications for replies (or at least I don't see anything in the notifications history here nor any emails about it).
I don't see how the
--copy-dependencies-onlyoption would be helpful though, especially since I don't see a matching option to continue building the APK afterwards, unless I'm supposed to run./gradlew assembleDebugor similar to do so.I did try running the same androiddeployqt command that Qt Creator seems to run but with the
--copy-dependencies-onlyoption added, then deleting the FluentWinUI3 style libraries to start with and then running./gradlew installDebug, which did seem to shrink the installed app's size in the emulator but made the app crash.I also tried to use the
QT_ANDROID_DEPLOYMENT_DEPENDENCIESCMake target property by setting it to all the dependencies reported by androiddeployqt's verbose output when run by Qt Creator, with that method when I remove the FluentWinUI3 style files from the list I do get a smaller APK and the app runs, however the Magnetometer object from the QtSensors library appears to break instead, it is no longer able to give me any readings, and it works again if I remove theQT_ANDROID_DEPLOYMENT_DEPENDENCIESCMake property. The Magnetometer object still refuses to work even after I add back that FluentWinUI3 stuff, so the number of dependencies reported by androiddeployqt is the same before and after I add the CMake property. I don't see any log entries even in debug mode, the start method of the magnetometer just returns false, the connectedToBackend property is false and the error code stays 0 so I can't tell exactly what the issue is (it's the same behavior I observe if I run the app on my Linux desktop natively which lacks the sensor at all).So, it seems like with either the
--copy-dependencies-onlyandroiddeployqt method or theQT_ANDROID_DEPLOYMENT_DEPENDENCIESCMake method there's a missing step somewhere that breaks things one way or the other. Although I do see that the documentation page for that CMake variable says that the order of the dependencies in the list matters, so next step for me will be to inspect the dependency order in the androiddeployqt verbose output and try rearranging things to see if that makes a difference, since the order is currently just the order androiddeployqt copies the files.