Build APK with docker: apk size issue (v3.2.0)

Describe the issue

I am building QField v3.2.0 apk with docker. The build is succesful but the apk file size seems to be huge ( ~ 600Mo) comparing to released apk on store ( less than 100Mo)

Reproduction steps

OS: Ubuntu 22.04 on wsl
Steps to reproduce the behavior:

  1. clone git project tag 3.2.0
  2. run cmd triplet=arm64-android ./scripts/build.sh

Expected behavior

APK file around 100Mo

Observed behavior

APK file around 600Mo

Screenshots and GIFs

Mobile (please complete the following information)

  • OS: API 33
  • QField version: 3.2.0

Additional information

  • Problem started happening recently, didn’t happen in an older version of QField: Yes v3.1.9 is ok
  • Problem can be reliably reproduced, doesn’t happen randomly: No

Imported from GitHub discussion by @qsavoye on 2024-03-19T13:28:25Z

qsavoye , size is caused by the build type is debug, which doesn’t strip the libraries to ease debugging (the primary use of these local docker builds to begin with).


Imported from GitHub comment by @nirvn on 2024-03-19T14:25:55Z

nirvn thank for the reply, i also modified the cmake build type to release in build-vcpkg.sh. It does not change apk size. And on other version such as 3.1.9, the docker compute me an apk file around 80Mo even in debug.


Imported from GitHub comment by @qsavoye on 2024-03-19T14:36:54Z

qsavoye , which .so have grown in size within the APK? The size differential definitively has to do with libs not being stripped. Did you try 3.1.9 or maybe an earlier build in the 3.1.x series? Prior to 3.1.5, we were not building the Qt libs themselves. That has changed in 3.1.5.


Imported from GitHub comment by @nirvn on 2024-03-19T14:51:13Z

nirvn

I made a test with the two last releases (3.1.9 and 3.2.0)

  1. git clone
  2. select the version tag
  3. run cmd triplet=arm64-android ./scripts/build.sh

by reading the all .so file in /build-arm64-android/src/app/android-build/libs/arm64-v8a, i obtain the following table (size are on Mo)

Lib 3.1.9 3.2.0 Variation
libssl.so 2.82 4.4 56%
libjson-c.so 0.23 0.25 9%
libcrypto.so 16.29 17.64 8%
libqml_QtQuick_Controls_Universal_impl_qtquickcontrols2universalstyleimplplugin_arm64-v8a.so 1.72 1.81 5%
libqfield_arm64-v8a.so 707.72 735.99 4%
libplugins_position_qtposition_android_arm64-v8a.so 1.65 1.7 3%
libplugins_imageformats_qico_arm64-v8a.so 0.44 0.45 2%
libQt6OpenGLWidgets_arm64-v8a.so 0.44 0.45 2%
libwebp.so 2.49 2.54 2%
libplugins_imageformats_qjpeg_arm64-v8a.so 0.5 0.51 2%
libxml2.so 6.92 7.04 2%
libpoly2tri.so 0 0.5
Total 1799.87 1833.8 2%
APK size 88.7 618 597%

qfieldVersionComparaison.xlsx

As we can there is no extra growth variation except for libssl. So maybe libqfield_arm64-v8a.so is not stripped, maybe due to new qgis version (3.36)?

I will continue my investigation on libqfield_arm64-v8a.so or on the bundle cmd to create the apk. I am not familiar with the last part, if you have any advice about it let me know.

Kind Regards


Imported from GitHub comment by @qsavoye on 2024-03-20T12:57:43Z

I used the old docker file version (3.1.9) custom with open jdk 17 instead of 11 on qfield 3.2.0 it seems to solve the size issue.

What is the main difference between the to files ? Android NDK/SDK version and installation ?


Imported from GitHub comment by @qsavoye on 2024-03-20T15:13:40Z

nirvn

I finaly figure out what cause my apk size issue. I was due to the downloaded NDK files in the docker. I don’t know why but if i install the NDK with the sdkmanager, the issue disapears.

I put my corrected dockerfile


FROM ubuntu:22.04

ENV ANDROID_NDK_VERSION=25.2.9519653

# Add apt packages

## vcpkg prerequisites
ENV APT_PACKAGES="git curl zip unzip tar"

## Common build prereqs
ENV APT_PACKAGES="$APT_PACKAGES g++ vim pkg-config cmake ninja-build ca-certificates"

ENV APT_PACKAGES="$APT_PACKAGES autoconf nasm bison python2 flex build-essential libtool libtool-bin gettext automake autoconf-archive"

## Python related
ENV APT_PACKAGES="$APT_PACKAGES python3-setuptools python3-pip python3-venv"

## freeglut
ENV APT_PACKAGES="$APT_PACKAGES libxi-dev libgl1-mesa-dev libglu1-mesa-dev mesa-common-dev libxrandr-dev libxxf86vm-dev"

# glfw3
ENV APT_PACKAGES="$APT_PACKAGES libxinerama-dev libxcursor-dev"

# qtbase
ENV APT_PACKAGES="$APT_PACKAGES libxext-dev libxfixes-dev libxrender-dev \
  libxcb1-dev libx11-xcb-dev libxcb-glx0-dev libxcb-util0-dev \
  libxkbcommon-dev libxcb-keysyms1-dev \
  libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync-dev \
  libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev \
  libxcb-render-util0-dev libxcb-xinerama0-dev libxcb-xkb-dev libxcb-xinput-dev \
  libxcb-cursor-dev libxkbcommon-x11-dev libcups2-dev"

## qtbase for android
ENV APT_PACKAGES="$APT_PACKAGES openjdk-17-jre-headless openjdk-17-jdk-headless"

RUN <<END_OF_SCRIPT bash
set -e
export DEBIAN_FRONTEND=noninteractive

# Apt prereqs itself
apt-get -y update
apt-get -y --no-install-recommends install ca-certificates

# Add apt repos

# Run apt things
apt-get -y update
apt-get -y dist-upgrade

apt-get -y --no-install-recommends install $APT_PACKAGES

curl -o /android-sdk-10406996.zip https://dl.google.com/android/repository/commandlinetools-linux-10406996_latest.zip
# curl -o /android-ndk-r25c-linux.zip https://dl.google.com/android/repository/android-ndk-r25c-linux.zip

# # Android NDK
# unzip /android-ndk-r25c-linux.zip
# rm -f android-ndk-r25c-linux.zip

# # Android SDK
unzip /android-sdk-10406996.zip -d android-sdk
rm -f android-sdk-10406996.zip

shopt -s extglob
mkdir /android-sdk/cmdline-tools/latest
mv /android-sdk/cmdline-tools/!(latest) /android-sdk/cmdline-tools/latest
yes | /android-sdk/cmdline-tools/latest/bin/sdkmanager --licenses
/android-sdk/cmdline-tools/latest/bin/sdkmanager "platforms;android-34" "build-tools;34.0.0" "platform-tools" "tools" "ndk;${ANDROID_NDK_VERSION}"
END_OF_SCRIPT

# ENV ANDROID_NDK_HOME /android-ndk-r25c
ENV ANDROID_SDK_ROOT /android-sdk
ENV ANDROID_NDK_HOME=${ANDROID_SDK_ROOT}/"ndk"/${ANDROID_NDK_VERSION}

WORKDIR /usr/src


Imported from GitHub comment by @qsavoye on 2024-08-29T07:00:09Z