Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

APK file size too big



  • Hi all,

    My current QML app using the following contents creates APK files of Release and Debug modes with the same size (!) resulting in about 18 MB!

    One .png file : 2.3 MB
    One .gif file: 3.5 MB
    Three .wave files totally: 65 KB
    One .icon file: 1 MB

    Code compromises a number of components all ending in about 600 lines of code.

    That is, ~7 MB for the files and ~11 MB for ~600 lines of code! Is it not weird?
    What is the reason for that, and how to solve it please? :(

    Moreover, why do both the Release and Debug modes produce an APK file with the same size? :(


  • Moderators

    @tomy said in APK file size too big:

    That is, ~7 MB for the files and ~11 MB for ~600 lines of code! Is it not weird?
    What is the reason for that, and how to solve it please? :(

    i guess you are also bundling the Qt libs with your APK?!
    You APK also contains all the QML modules if it is a QML app.



  • @raven-worx

    i guess you are also bundling the Qt libs with your APK?!

    I don't know of that but I believe I haven't used any part of Qt in this QML project

    0_1551645409970_Capture.PNG

    You APK also contains all the QML modules if it is a QML app.

    Yes, it can be installed on Android devices so these stuff probably are needed for that intention. But isn't it still too large?


  • Moderators

    @tomy said in APK file size too big:

    I don't know of that but I believe I haven't used any part of Qt in this QML project

    You may want to read this.

    Also obviously your 4 imports require some Qt libs no? How else could you use Qt without using its libs?!

    btw. nowadays an app size of 20MB is rather common..



  • @raven-worx

    You may want to read this.

    Thanks. I read and figured out most (if not all) of it.
    For creating an APK (a standalone Android app) there's not any lead how to decrease the size there!

    Also obviously your 4 imports require some Qt libs no? How else could you use Qt without using its libs?!

    I indeed have not that perfect information about those advanced areas of QML and am rather novice in it. But if they're of Qt, they must be imported because they're required for the program. There's, however, one exception: QtQuick.Controls. I used it for having a few buttons, and it's not difficult to define a custom myButton but it's not obvious for me how much it affects the size of the final APK file if we remove that import and use a custom button. Is this worth for stepping for that, please?

    btw. nowadays an app size of 20MB is rather common..

    Yeah, but are they common if they contain only about 600 lines of code plus few media files all with the size of 7 MB?

    On Release and Debug modes, I thought the Debug mode would give us a lighter version of the executable file compared to Debug! But in reality, there is no different aspect in size between the two! :(


  • Moderators

    @tomy said in APK file size too big:

    On Release and Debug modes, I thought the Debug mode would give us a lighter version of the executable file compared to Debug! But in reality, there is no different aspect in size between the two! :(

    Hi,

    I think I mentioned this before, but you have to actually sign your apk file, so that the apk size will be reduced.

    You have to create a (selfsigned)certificate (can be done my yourself).
    You can do that via QtCreator.
    Open your project,
    select project settings, left hand selection bar
    select "Build Android apk"
    click on create, id you do not have a certificate yet, or select the certificate file and enter your password.

    should reduce the size by about 30-40%



  • @J.Hilk Hi,

    I firstly filled in the fields for the Release mode for Arm7 and used two different passwords, one for keystore and another for Certificate, then saved it.

    After that changed the kit from Release to Debug and used the previous keystore file. But there is a warning sign on that area.

    0_1551708573447_Capture.PNG

    I tuned out that sign and Built the app using that kit on Debug. It gave an APK file of 17.2 MB. The previous (non-signed) version was 17.9! :(

    Anyways, I went to Build the app using Release to hopefully have a more reduced file. But it gave a file of 16.9 MB! :(

    That is, in its best state, it was decreased by ~ %6! :(
    What is the problem, now, please? There is much difference between %6 and %30/%40. :(


  • Moderators

    @tomy
    signing is only allowed for release builds, IIRC. Therefore the warning

    17 mb is about the size a Qt Qml app will have. Mine currently has 15.

    a few things to check to possibly reduce the size

    • Make sure your import the same versions in all your files
    • make sure not to import, what you're not using.
    • check your pro file for module add ons that you're actually not using (QT + = xxxx)
    • completely delete your build folder after setting to release and signing.


  • @J.Hilk

    Ahmeds 17 mb is about the size a Qt Qml app will have.

    Ahmeds?

    a few things to check to possibly reduce the size

    • Make sure your import the same versions in all your files

    I don't change them in a project for its all life time, because at the beginning I add the newest versions always.

    • make sure not to import, what you're not using.

    the only import directive was QtQucik.controls. I explained it in above prior posts. Please have a look, if possible. And if it's effective I go after that.

    • check your pro file for module add ons that you're actually not using (QT + = xxxx)

    Here is .pro:

    QT += quick
    CONFIG += c++11
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Refer to the documentation for the
    # deprecated API to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    DISTFILES += \
        android/AndroidManifest.xml \
        android/gradle/wrapper/gradle-wrapper.jar \
        android/gradlew \
        android/res/values/libs.xml \
        android/build.gradle \
        android/gradle/wrapper/gradle-wrapper.properties \
        android/gradlew.bat
    
    contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
        ANDROID_PACKAGE_SOURCE_DIR = \
            $$PWD/android
    }
    
    • completely delete your build folder after setting to release and signing.

    I did it.



  • @tomy 18 MB is not that big. Look at the storage used by other apps on your device. Mine's 55 MB. I asked a similar question last week and didn't get any replies. What I figured out is that after building with Qt Creator, you can import the project into Android Studio as a gradle project, then delete some unnecessary shared objects, like unused Quick Controls 2 styles. That worked but I only saved a few MB. I could not figure out how to do it from Qt Creator.

    My app size went from 39 MB to 55 MB after upgrading from Qt 5.9 to 5.12.



  • @Tom_H
    Aw, that's strange about %40 load just by upgrading to 5.12.
    Probably, if my app was created by 5.9, it would have had lower size. But anyhow, yeah 16.9 MB is not that big, but what I was scared about is redundant load on this which could be the same in other bigger apps as well and subsequently, a lower quality output.
    Yet, I don't think there's some import library used needlessly in the app.
    Thanks for your reply.



  • @tomy I should clarify that 55 MB is the size of the installed app on my device, which is on par with other apps. The APK size is 13 MB.



  • @Tom_H
    do you mean the app file has 13 MB contents as its size but when it's installed it occupies 55 MB on the storage of your android device?
    I haven't checked my app's size out on my device after installing it.



  • @tomy Yes, the size of myapp.apk is 13 MB, but after installing on the device the app consumes 55 MB as shown under Settings>Storage>Apps.


Log in to reply