3131#include " gradle_export_util.h"
3232
3333#include " core/config/project_settings.h"
34+ #include " modules/regex/regex.h"
3435
3536int _get_android_orientation_value (DisplayServer::ScreenOrientation screen_orientation) {
3637 switch (screen_orientation) {
@@ -272,6 +273,19 @@ String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset) {
272273}
273274
274275String _get_activity_tag (const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug) {
276+ String export_plugins_activity_element_contents;
277+ Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton ()->get_export_plugins ();
278+ for (int i = 0 ; i < export_plugins.size (); i++) {
279+ if (export_plugins[i]->supports_platform (p_export_platform)) {
280+ const String contents = export_plugins[i]->get_android_manifest_activity_element_contents (p_export_platform, p_debug);
281+ if (!contents.is_empty ()) {
282+ export_plugins_activity_element_contents += contents;
283+ export_plugins_activity_element_contents += " \n " ;
284+ }
285+ }
286+ }
287+
288+ // Update the GodotApp activity tag.
275289 String orientation = _get_android_orientation_label (DisplayServer::ScreenOrientation (int (p_export_platform->get_project_setting (p_preset, " display/window/handheld/orientation" ))));
276290 String manifest_activity_text = vformat (
277291 " <activity android:name=\" .GodotApp\" "
@@ -284,6 +298,21 @@ String _get_activity_tag(const Ref<EditorExportPlatform> &p_export_platform, con
284298 orientation,
285299 bool_to_string (bool (p_export_platform->get_project_setting (p_preset, " display/window/size/resizable" ))));
286300
301+ // *LAUNCHER and *HOME categories should only go to the activity-alias.
302+ Ref<RegEx> activity_content_to_remove_regex = RegEx::create_from_string (R"delim( <category\s+android:name\s*=\s*"\S+(LAUNCHER|HOME)"\s*\/>)delim" );
303+ String updated_export_plugins_activity_element_contents = activity_content_to_remove_regex->sub (export_plugins_activity_element_contents, " " , true );
304+
305+ manifest_activity_text += updated_export_plugins_activity_element_contents;
306+
307+ manifest_activity_text += " </activity>\n " ;
308+
309+ // Update the GodotAppLauncher activity tag.
310+ manifest_activity_text += " <activity-alias\n "
311+ " tools:node=\" mergeOnlyAttributes\"\n "
312+ " android:name=\" .GodotAppLauncher\"\n "
313+ " android:targetActivity=\" .GodotApp\"\n "
314+ " android:exported=\" true\" >\n " ;
315+
287316 manifest_activity_text += " <intent-filter>\n "
288317 " <action android:name=\" android.intent.action.MAIN\" />\n "
289318 " <category android:name=\" android.intent.category.DEFAULT\" />\n " ;
@@ -305,18 +334,12 @@ String _get_activity_tag(const Ref<EditorExportPlatform> &p_export_platform, con
305334
306335 manifest_activity_text += " </intent-filter>\n " ;
307336
308- Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton ()->get_export_plugins ();
309- for (int i = 0 ; i < export_plugins.size (); i++) {
310- if (export_plugins[i]->supports_platform (p_export_platform)) {
311- const String contents = export_plugins[i]->get_android_manifest_activity_element_contents (p_export_platform, p_debug);
312- if (!contents.is_empty ()) {
313- manifest_activity_text += contents;
314- manifest_activity_text += " \n " ;
315- }
316- }
317- }
337+ // Hybrid categories should only go to the actual 'GodotApp' activity.
338+ Ref<RegEx> activity_alias_content_to_remove_regex = RegEx::create_from_string (R"delim( <category\s+android:name\s*=\s*"org.godotengine.xr.hybrid.(IMMERSIVE|PANEL)"\s*\/>)delim" );
339+ String updated_export_plugins_activity_alias_element_contents = activity_alias_content_to_remove_regex->sub (export_plugins_activity_element_contents, " " , true );
340+ manifest_activity_text += updated_export_plugins_activity_alias_element_contents;
318341
319- manifest_activity_text += " </activity>\n " ;
342+ manifest_activity_text += " </activity-alias >\n " ;
320343 return manifest_activity_text;
321344}
322345
0 commit comments