[Interest] Android: build:gradle plugin: adjust version depending on Qt version

Niels Mayer nielsmayer at gmail.com
Tue Feb 20 20:34:00 CET 2024


I've solved this class of problem by having multiple "android"
subdirectories, which are selected based on Qt version. This allows for
multiple AndroidManifest files to handle version-based changes, such as
adding androidx.core.content.FileProvider for Qt6.6 and beyond to handle
the android-native file dialog. It also allows for multiple
gradle.properties and build.gradle to handle changes in gradle versions,
including different jvmargs, inclusion of androidx, etc. The downside is
maintaining multiple AndroidManifest build.gradle and gradle.properties
files, which are mostly the same other than some minor changes required by
different versions of Qt.

In QMake, I do the following

android {
equals(QT_MAJOR_VERSION, 6):greaterThan(QT_MINOR_VERSION, 5) { ##for Qt6.6,
Qt6.7 and beyond use $$PWD/android
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    OTHER_FILES               += $$PWD/android/AndroidManifest.xml
}
else:equals(QT_MAJOR_VERSION, 6) { ##for Qt6.2, Qt6.3, Qt6.4, Qt6.5 use
$$PWD/android65
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android65
    OTHER_FILES               += $$PWD/android65/AndroidManifest.xml
}
else:equals(QT_MAJOR_VERSION, 5) {                                   ##for
Qt5.15.X use $$PWD/android5
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android5
    OTHER_FILES               += $$PWD/android5/AndroidManifest.xml
}
else {
     error("Unsupported version Qt$$QT_VERSION for Android
$$ANDROID_TARGET_ARCH -- Qt5.15 or Qt6 required")
}
}

Then in android/build.gradle ...
        classpath 'com.android.tools.build:gradle:7.4.1'
in android65/build.gradle ...
        classpath 'com.android.tools.build:gradle:7.2.1'
in android5/build.gradle
        classpath 'com.android.tools.build:gradle:3.6.0'

TODO: I will need to add android66 subdir to handle Qt6.6 and update
the 'android' subdir to handle Qt6.7, 6.8 and beyond. But since the
prereleases and betas still "work" with gradle 7.4.1, I haven't yet updated
the above technique yet for 6.7 or 6.8, which require "Gradle 8.3 and AGP
7.4.1" per https://doc-snapshots.qt.io/qt6-6.7/android.html ...

-- Niels
http://www.nielsmayer.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240220/7371c41c/attachment.htm>


More information about the Interest mailing list