Android 6 and above produces uncompressed native libraries that
are only part of the APK by default. However, Qt had this behavior
explicitly disabled via packagingOptions.jniLibs.useLegacyPackaging
Gradle flag (previously extractNativeLibs manifest flag) because
we didn't support loading libraries directly from the APK.
This patch adds support for reading and loading shared libraries
directly from the APK without having them extracted to disk. Enabling
this might increase slightly the total size of produced APKs, but
saves on disk space after installation and also on update sizes from
the Play Store and slightly faster startups [1][2].
Loading libraries on the Java side is handled by System.loadLibrary().
On C++, dlopen(3) can directly handle library paths relative to the
APK file [3] which would save us the need to add custom code that calls
android_dlopen_ext() [4] which works with compressed libraries then
using AssetFileDescriptor and having to manage its file descriptor
manually.
To ensure proper integration with various Qt APIs and modules, this
adds a QAbstractFileEngine/Iterator implementations to allow reading
and listing APK files. Since, the files are expected to not change,
they are cached once at startup and re-used thereafter. The engine
implementation allows reading the libraries content using Android's
AssetManager. Also, it allows mapping the libraries directly to
memory to allow proper integration with QPluginLoader.
For plugins, the native libs dir inside the APK is added to Qt and
QML plugins search paths.
With this patch, both compressed and uncompressed libs should work,
to ensure this, an auto test is added with 'useLegacyPackaging true'
to make sure both scenarios still works.
[ChangeLog][Android] Add support for uncompressed native libraries
within APKs.
[1] https://android-developers.googleblog.com/2016/07/improvements-for-
smaller-app-downloads.html
[2] https://developer.android.com/guide/topics/manifest/application-
element#extractNativeLibs
[3] https://android.googlesource.com/platform/bionic/+/master/android-
changes-for-ndk-developers.md#Opening-shared-libraries-directly-from-an-
APK
[4] https://developer.android.com/ndk/reference/group/
libdl#android_dlopen_ext
Fixes: QTBUG-61072
Fixes: QTBUG-97650
Change-Id: Ica6c4cc9e5bd8f3610829b76b64bf599339435d9
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>