From 1de8d27ea8478ef0d3c7f9038f0a801e890dc0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20P=C3=A9rez=20Alonso?= <119585865+rubenp02@users.noreply.github.com> Date: Fri, 29 Nov 2024 21:27:49 +0100 Subject: [PATCH] Improve flexibility in Android custom builds (#12150) * Add custom AndroidManifest.xml file The default AndroidManifest.xml found in android/ but with the app name changed to "Custom QGroundControl" * Improve flexibility in Android custom builds Modified the build system to prioritize files under custom/android/ over android/ for Android deployment in custom builds. If custom/android/ exists and contains files, these are overlaid onto the default android/ files, creating a combined Android package deployment template in the build directory. This enables customization of any aspect of the Android deployment in custom builds without modifying the upstream android/ directory. Additionally, any changes in either directory will trigger the CMake configuration step in order to update the combined directory. This change also restores support for the custom Android icons under custom/android/, which had been disabled during the transition to CMake. Additional note: New CMake properties for Android deployment (including QT_ANDROID_APP_NAME, QT_ANDROID_APP_ICON, and QT_ANDROID_PACKAGE_NAME) are being added to Qt, which will streamline the more basic aspects of Android deployment customization even further. But this current solution will probably remain useful for cases where more extensive customization is required. --- CMakeLists.txt | 28 +++++- custom-example/android/AndroidManifest.xml | 109 +++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 custom-example/android/AndroidManifest.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b76489844a..50614217dc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -416,12 +416,38 @@ elseif(ANDROID) endif() set(ANDROID_VERSION_CODE "${ANDROID_PLATFORM_ARCHITECTURE_CODE}${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}") + if(NOT QGC_CUSTOM_BUILD) + set(QGC_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/android) + else() + set(CUSTOM_ANDROID_DIR "${CMAKE_SOURCE_DIR}/custom/android") + if(EXISTS "${CUSTOM_ANDROID_DIR}") + file(GLOB CUSTOM_ANDROID_FILES "${CUSTOM_ANDROID_DIR}/*") + if(CUSTOM_ANDROID_FILES) + message(STATUS "Custom Android package template found. Overlaying custom files...") + set(DEFAULT_ANDROID_DIR "${CMAKE_SOURCE_DIR}/android") + set(FINAL_ANDROID_DIR "${CMAKE_BINARY_DIR}/custom/android") + file(COPY "${DEFAULT_ANDROID_DIR}/." DESTINATION "${FINAL_ANDROID_DIR}") + file(COPY "${CUSTOM_ANDROID_DIR}/." DESTINATION "${FINAL_ANDROID_DIR}") + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS + "${DEFAULT_ANDROID_DIR}/" + "${CUSTOM_ANDROID_DIR}/" + ) + set(QGC_ANDROID_PACKAGE_SOURCE_DIR "${FINAL_ANDROID_DIR}" CACHE STRING "Path to a custom Android package template" FORCE) + message(STATUS "Android package template path will be set to: ${QGC_ANDROID_PACKAGE_SOURCE_DIR}") + else() + message(STATUS "Custom Android package template empty. Using default.") + endif() + else() + message(STATUS "No custom Android package template found. Using default.") + endif() + endif() + set_target_properties(${PROJECT_NAME} PROPERTIES # QT_ANDROID_ABIS ${ANDROID_ABI} QT_ANDROID_MIN_SDK_VERSION 25 QT_ANDROID_TARGET_SDK_VERSION 35 - QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/android + QT_ANDROID_PACKAGE_SOURCE_DIR "${QGC_ANDROID_PACKAGE_SOURCE_DIR}" QT_ANDROID_VERSION_NAME ${CMAKE_PROJECT_VERSION} QT_ANDROID_VERSION_CODE ${ANDROID_VERSION_CODE} # QT_QML_ROOT_PATH ${CMAKE_SOURCE_DIR} diff --git a/custom-example/android/AndroidManifest.xml b/custom-example/android/AndroidManifest.xml new file mode 100644 index 00000000000..9130406b01b --- /dev/null +++ b/custom-example/android/AndroidManifest.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +