qmake: Add variables for setting the version number and name in Android

This makes it much easier to have the version information set for an
Android APK without having to manually modify the AndroidManifest.xml
each time.

[ChangeLog][Android][qmake] Can now set the version name and code for
Android using ANDROID_VERSION_NAME and ANDROID_VERSION_CODE respectively
in the pro file.

Change-Id: Ie6813bc3a7444f7baa5e772b93bc2695d9b81e57
Done-with: Markus Maier <markus.maier@rosenberger.de>
Reviewed-by: Markus Maier <markus.maier@rosenberger.de>
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
Andy Shaw 2018-10-15 09:23:26 +02:00
parent 29d5a287ab
commit 9435526d50
3 changed files with 31 additions and 1 deletions

View File

@ -58,6 +58,14 @@ contains(TEMPLATE, ".*app"):!build_pass:!android-embedded {
!isEmpty(ANDROID_PACKAGE_SOURCE_DIR): \
FILE_CONTENT += " \"android-package-source-directory\": $$emitString($$ANDROID_PACKAGE_SOURCE_DIR),"
# Android-specific version string
!isEmpty(ANDROID_VERSION_NAME): \
FILE_CONTENT += " \"android-version-name\": $$emitString($$ANDROID_VERSION_NAME),"
# Android-specific version number
!isEmpty(ANDROID_VERSION_CODE): \
FILE_CONTENT += " \"android-version-code\": $$emitString($$ANDROID_VERSION_CODE),"
!isEmpty(ANDROID_EXTRA_LIBS): \
FILE_CONTENT += " \"android-extra-libs\": $$emitString($$join(ANDROID_EXTRA_LIBS, ",")),"

View File

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<manifest package="org.qtproject.example" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<manifest package="org.qtproject.example" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="-- %%INSERT_VERSION_NAME%% --" android:versionCode="-- %%INSERT_VERSION_CODE%% --" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.

View File

@ -148,6 +148,10 @@ struct Options
QString rootPath;
QStringList qmlImportPaths;
// Versioning
QString versionName;
QString versionCode;
// lib c++ path
QString stdCppPath;
QString stdCppName = QStringLiteral("gnustl_shared");
@ -756,6 +760,22 @@ bool readInputFile(Options *options)
options->androidSourceDirectory = androidSourcesDirectory.toString();
}
{
const QJsonValue androidVersionName = jsonObject.value(QStringLiteral("android-version-name"));
if (!androidVersionName.isUndefined())
options->versionName = androidVersionName.toString();
else
options->versionName = QStringLiteral("1.0");
}
{
const QJsonValue androidVersionCode = jsonObject.value(QStringLiteral("android-version-code"));
if (!androidVersionCode.isUndefined())
options->versionCode = androidVersionCode.toString();
else
options->versionCode = QStringLiteral("1");
}
{
const QJsonValue applicationBinary = jsonObject.value(QStringLiteral("application-binary"));
if (applicationBinary.isUndefined()) {
@ -1324,6 +1344,8 @@ bool updateAndroidManifest(Options &options)
replacements[QLatin1String("-- %%INSERT_LOCAL_LIBS%% --")] = localLibs.join(QLatin1Char(':'));
replacements[QLatin1String("-- %%INSERT_LOCAL_JARS%% --")] = options.localJars.join(QLatin1Char(':'));
replacements[QLatin1String("-- %%INSERT_INIT_CLASSES%% --")] = options.initClasses.join(QLatin1Char(':'));
replacements[QLatin1String("-- %%INSERT_VERSION_NAME%% --")] = options.versionName;
replacements[QLatin1String("-- %%INSERT_VERSION_CODE%% --")] = options.versionCode;
replacements[QLatin1String("package=\"org.qtproject.example\"")] = QString::fromLatin1("package=\"%1\"").arg(options.packageName);
replacements[QLatin1String("-- %%BUNDLE_LOCAL_QT_LIBS%% --")]
= (options.deploymentMechanism == Options::Bundled) ? QString::fromLatin1("1") : QString::fromLatin1("0");