diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp
index 4d87b4537b0b..cecadacf77e3 100644
--- a/platform/android/export/export_plugin.cpp
+++ b/platform/android/export/export_plugin.cpp
@@ -214,6 +214,18 @@ static const char *MISMATCHED_VERSIONS_MESSAGE = "Android build version mismatch
static const char *GDEXTENSION_LIBS_PATH = "libs/gdextensionlibs.json";
+// This template string must always match the content of 'platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml'.
+static const String ICON_XML_TEMPLATE =
+ "\n"
+ "\n"
+ " \n"
+ " \n"
+ "%s" // Placeholder for the optional monochrome tag.
+ "";
+
+static const String ICON_XML_PATH = "res/mipmap-anydpi-v26/icon.xml";
+static const String THEMED_ICON_XML_PATH = "res/mipmap-anydpi-v26/themed_icon.xml";
+
static const int icon_densities_count = 6;
static const char *launcher_icon_option = PNAME("launcher_icons/main_192x192");
static const char *launcher_adaptive_icon_foreground_option = PNAME("launcher_icons/adaptive_foreground_432x432");
@@ -1689,7 +1701,7 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref &
path = static_cast(p_preset->get(launcher_adaptive_icon_monochrome_option)).strip_edges();
if (!path.is_empty()) {
print_verbose("Loading adaptive monochrome icon from " + path);
- ImageLoader::load_image(path, background);
+ ImageLoader::load_image(path, monochrome);
}
}
@@ -1700,6 +1712,8 @@ void EditorExportPlatformAndroid::_copy_icons_to_gradle_project(const Ref &p_monochrome) {
String gradle_build_dir = ExportTemplateManager::get_android_build_directory(p_preset);
+ String monochrome_tag = "";
+
// Prepare images to be resized for the icons. If some image ends up being uninitialized,
// the default image from the export template will be used.
@@ -1733,8 +1747,12 @@ void EditorExportPlatformAndroid::_copy_icons_to_gradle_project(const Ref\n";
}
}
+
+ // Finalize the icon.xml by formatting the template with the optional monochrome tag.
+ store_string_at_path(gradle_build_dir.path_join(ICON_XML_PATH), vformat(ICON_XML_TEMPLATE, monochrome_tag));
}
Vector EditorExportPlatformAndroid::get_enabled_abis(const Ref &p_preset) {
@@ -3398,6 +3416,11 @@ Error EditorExportPlatformAndroid::export_project_helper(const Refget("apk_expansion/public_key");
Vector invalid_abis(enabled_abis);
+
+ //To temporarily store icon xml data.
+ Vector themed_icon_xml_data;
+ int icon_xml_compression_method = -1;
+
while (ret == UNZ_OK) {
//get filename
unz_file_info info;
@@ -3427,6 +3450,20 @@ Error EditorExportPlatformAndroid::export_project_helper(const Refis_empty()) {
+ // Defer processing of icon.xml until after themed_icon.xml is read.
+ icon_xml_compression_method = info.compression_method;
+ skip = true;
+ }
+ }
+
if (file.ends_with(".png") && file.contains("mipmap")) {
for (int i = 0; i < icon_densities_count; ++i) {
if (main_image.is_valid() && !main_image->is_empty()) {
@@ -3496,6 +3533,28 @@ Error EditorExportPlatformAndroid::export_project_helper(const Refis_empty()) {
+ print_line("ADDING: " + ICON_XML_PATH + " (replacing with themed_icon.xml data)");
+
+ const bool uncompressed = icon_xml_compression_method == 0;
+ zip_fileinfo zipfi = get_zip_fileinfo();
+
+ zipOpenNewFileInZip(unaligned_apk,
+ ICON_XML_PATH.utf8().get_data(),
+ &zipfi,
+ nullptr,
+ 0,
+ nullptr,
+ 0,
+ nullptr,
+ uncompressed ? 0 : Z_DEFLATED,
+ Z_DEFAULT_COMPRESSION);
+
+ zipWriteInFileInZip(unaligned_apk, themed_icon_xml_data.ptr(), themed_icon_xml_data.size());
+ zipCloseFileInZip(unaligned_apk);
+ }
+
if (!invalid_abis.is_empty()) {
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Missing libraries in the export template for the selected architectures: %s. Please build a template with all required libraries, or uncheck the missing architectures in the export preset."), join_abis(invalid_abis, ", ", false)));
CLEANUP_AND_RETURN(ERR_FILE_NOT_FOUND);
diff --git a/platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml b/platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml
index bb2ae6bee56a..0ac805f8f39d 100644
--- a/platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml
+++ b/platform/android/java/lib/res/mipmap-anydpi-v26/icon.xml
@@ -1,6 +1,8 @@
+
-
diff --git a/platform/android/java/lib/res/mipmap-anydpi-v26/themed_icon.xml b/platform/android/java/lib/res/mipmap-anydpi-v26/themed_icon.xml
new file mode 100644
index 000000000000..95457ca7d256
--- /dev/null
+++ b/platform/android/java/lib/res/mipmap-anydpi-v26/themed_icon.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+