Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to exclude unnecessary libraries from Android APK?

How to exclude unnecessary libraries from Android APK?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 135 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    X_m7
    wrote last edited by X_m7
    #1

    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.Material in all my QML apps instead of just QtQuick.Controls as well as specifying Style=Material in the [Controls] section of qtquickcontrols2.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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi and welcome to devnet,

      From a quick look at the androiddeployqt documentation, I think you are looking for the --copy-dependencies-only option. The Dependencies Detection section might also be of interest.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • X Offline
        X Offline
        X_m7
        wrote last edited by
        #3

        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-only option 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 assembleDebug or similar to do so.

        I did try running the same androiddeployqt command that Qt Creator seems to run but with the --copy-dependencies-only option 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_DEPENDENCIES CMake 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 the QT_ANDROID_DEPLOYMENT_DEPENDENCIES CMake 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-only androiddeployqt method or the QT_ANDROID_DEPLOYMENT_DEPENDENCIES CMake 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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved