CMake:Android: add property QT_ANDROID_APP_NAME to set app name

With this property, a user can set the app's name directly from CMake
without having to manaully manage a custom AndroidManifest.xml file.

Fixes: QTBUG-87982
Fixes: QTBUG-121825
Fixes: QTCREATORBUG-17863
Change-Id: Ic12e13b58efbc4fb2f18be6fc854b585988485bf
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Assam Boudjelthia 2024-09-07 13:33:11 +03:00
parent 41b72465d8
commit c768ec64bb
7 changed files with 50 additions and 2 deletions

View File

@ -77,6 +77,7 @@ Qt sets the following manifest configuration by default:
\row
\li android:label
\li The application name label. Default value is the Qt project's target name.
This can be set using \l {QT_ANDROID_APP_NAME}.
\row
\li android:hardwareAccelerated
\li Sets hardware acceleration preference. The default value is \c true.

View File

@ -217,10 +217,14 @@ function(qt6_android_generate_deployment_settings target)
_qt_internal_add_android_deployment_property(file_contents "android-package-source-directory"
${target} "_qt_android_native_package_source_dir")
# version code
# package name
_qt_internal_add_android_deployment_property(file_contents "android-package-name"
${target} "QT_ANDROID_PACKAGE_NAME")
# app name
_qt_internal_add_android_deployment_property(file_contents "android-app-name"
${target} "QT_ANDROID_APP_NAME")
# version code
_qt_internal_add_android_deployment_property(file_contents "android-version-code"
${target} "QT_ANDROID_VERSION_CODE")

View File

@ -299,6 +299,35 @@ For more information, see Android's
\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}
*/
/*!
\page cmake-target-property-qt-android-app-name.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
\title QT_ANDROID_APP_NAME
\target cmake-target-property-QT_ANDROID_APP_NAME
\ingroup cmake-android-manifest-properties
\summary {The Android app's name.}
\cmakepropertysince 6.9
\cmakepropertyandroidonly
Specifies the app's name that's shown in the launcher. This is human readable name
of the app, and it is different from the \l {QT_ANDROID_PACKAGE_NAME}{package name}
of the app. This doesn't do anything if the name is set explicitly in the
\c {AndroidManifest.xml}.
\badcode
set_target_properties(${target} PROPERTIES
QT_ANDROID_APP_NAME "Gallery"
)
\endcode
\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}
\sa {QT_ANDROID_PACKAGE_NAME}
*/
/*!
\page cmake-target-property-qt-android-version-code.html
\ingroup cmake-properties-qtcore

View File

@ -64,6 +64,7 @@ how to accomplish this.
\li \l{cmake-target-property-QT_ANDROID_PACKAGE_SOURCE_DIR}{QT_ANDROID_PACKAGE_SOURCE_DIR}
\li \l{cmake-target-property-QT_ANDROID_TARGET_SDK_VERSION}{QT_ANDROID_TARGET_SDK_VERSION}
\li \l{cmake-target-property-QT_ANDROID_PACKAGE_NAME}{QT_ANDROID_PACKAGE_NAME}
\li \l{cmake-target-property-QT_ANDROID_APP_NAME}{QT_ANDROID_APP_NAME}
\li \l{cmake-target-property-QT_ANDROID_VERSION_NAME}{QT_ANDROID_VERSION_NAME}
\li \l{cmake-target-property-QT_ANDROID_VERSION_CODE}{QT_ANDROID_VERSION_CODE}
\li \l{cmake-target-property-QT_QML_IMPORT_PATH}{QT_QML_IMPORT_PATH}

View File

@ -191,6 +191,7 @@ struct Options
DeploymentMechanism deploymentMechanism;
QString systemLibsPath;
QString packageName;
QString appName;
QStringList extraLibs;
QHash<QString, QStringList> archExtraLibs;
QStringList extraPlugins;
@ -1371,6 +1372,14 @@ bool readInputFile(Options *options)
}
}
{
const QJsonValue androidAppName = jsonObject.value("android-app-name"_L1);
if (!androidAppName.isUndefined())
options->appName = androidAppName.toString();
else
options->appName = options->applicationBinary;
}
{
using ItFlag = QDirListing::IteratorFlag;
const QJsonValue deploymentDependencies = jsonObject.value("deployment-dependencies"_L1);
@ -1843,7 +1852,7 @@ bool updateAndroidManifest(Options &options)
fprintf(stdout, " -- AndroidManifest.xml \n");
QHash<QString, QString> replacements;
replacements[QStringLiteral("-- %%INSERT_APP_NAME%% --")] = options.applicationBinary;
replacements[QStringLiteral("-- %%INSERT_APP_NAME%% --")] = options.appName;
replacements[QStringLiteral("-- %%INSERT_APP_ARGUMENTS%% --")] = options.applicationArguments;
replacements[QStringLiteral("-- %%INSERT_APP_LIB_NAME%% --")] = options.applicationBinary;
replacements[QStringLiteral("-- %%INSERT_VERSION_NAME%% --")] = options.versionName;

View File

@ -30,6 +30,7 @@ set_target_properties(${target} PROPERTIES
QT_ANDROID_SDK_BUILD_TOOLS_REVISION "23.0.2"
QT_ANDROID_MIN_SDK_VERSION "1"
QT_ANDROID_TARGET_SDK_VERSION "2"
QT_ANDROID_APP_NAME "Android Deployment Settings Test"
QT_ANDROID_PACKAGE_NAME "org.qtproject.android_deployment_settings_test"
QT_ANDROID_DEPLOYMENT_DEPENDENCIES "dep1.so;dep2.so;dep3.so"
QT_ANDROID_DEPLOYMENT_SETTINGS_FILE "attempt_to_rewrite.json"
@ -54,6 +55,7 @@ set_target_properties(${target} PROPERTIES
QT_ANDROID_SDK_BUILD_TOOLS_REVISION "23.0.2"
QT_ANDROID_MIN_SDK_VERSION "1"
QT_ANDROID_TARGET_SDK_VERSION "2"
QT_ANDROID_APP_NAME "Android Deployment Settings Test"
QT_ANDROID_PACKAGE_NAME "org.qtproject.android_deployment_settings_test"
QT_ANDROID_DEPLOYMENT_DEPENDENCIES "dep1.so;dep2.so;dep3.so"
QT_ANDROID_EXTRA_LIBS

View File

@ -78,6 +78,8 @@ void tst_android_deployment_settings::DeploymentSettings_data()
<< "2";
QTest::newRow("android-package-name") << "android-package-name"
<< "org.qtproject.android_deployment_settings_test";
QTest::newRow("android-app-name") << "android-app-name"
<< "Android Deployment Settings Test";
}
void tst_android_deployment_settings::DeploymentSettings()