Skip to content

Commit

Permalink
Add support for export plugins to modify the Android prebuilt manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Feb 22, 2025
1 parent 394508d commit 82c5a0f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
8 changes: 8 additions & 0 deletions doc/classes/EditorExportPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@
Return [code]true[/code] if the plugin supports the given [param platform].
</description>
</method>
<method name="_update_android_prebuilt_manifest" qualifiers="virtual const">
<return type="PackedByteArray" />
<param index="0" name="platform" type="EditorExportPlatform" />
<param index="1" name="manifest_data" type="PackedByteArray" />
<description>
Provide access to the Android prebuilt manifest and allows the plugin to modify it if needed.
</description>
</method>
<method name="add_file">
<return type="void" />
<param index="0" name="path" type="String" />
Expand Down
7 changes: 7 additions & 0 deletions editor/export/editor_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ String EditorExportPlugin::get_android_manifest_element_contents(const Ref<Edito
return ret;
}

PackedByteArray EditorExportPlugin::update_android_prebuilt_manifest(const Ref<EditorExportPlatform> &p_export_platform, const PackedByteArray &p_manifest_data) const {
PackedByteArray ret;
GDVIRTUAL_CALL(_update_android_prebuilt_manifest, p_export_platform, p_manifest_data, ret);
return ret;
}

PackedStringArray EditorExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {
PackedStringArray ret;
GDVIRTUAL_CALL(_get_export_features, p_platform, p_debug, ret);
Expand Down Expand Up @@ -369,4 +375,5 @@ void EditorExportPlugin::_bind_methods() {
GDVIRTUAL_BIND(_get_android_manifest_activity_element_contents, "platform", "debug");
GDVIRTUAL_BIND(_get_android_manifest_application_element_contents, "platform", "debug");
GDVIRTUAL_BIND(_get_android_manifest_element_contents, "platform", "debug");
GDVIRTUAL_BIND(_update_android_prebuilt_manifest, "platform", "manifest_data");
}
2 changes: 2 additions & 0 deletions editor/export/editor_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class EditorExportPlugin : public RefCounted {
GDVIRTUAL2RC(String, _get_android_manifest_activity_element_contents, const Ref<EditorExportPlatform> &, bool);
GDVIRTUAL2RC(String, _get_android_manifest_application_element_contents, const Ref<EditorExportPlatform> &, bool);
GDVIRTUAL2RC(String, _get_android_manifest_element_contents, const Ref<EditorExportPlatform> &, bool);
GDVIRTUAL2RC(PackedByteArray, _update_android_prebuilt_manifest, const Ref<EditorExportPlatform> &, const PackedByteArray &);

virtual bool _begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features); // Return true if this plugin does property export customization
virtual Ref<Resource> _customize_resource(const Ref<Resource> &p_resource, const String &p_path); // If nothing is returned, it means do not touch (nothing changed). If something is returned (either the same or a different resource) it means changes are made.
Expand Down Expand Up @@ -175,6 +176,7 @@ class EditorExportPlugin : public RefCounted {
virtual String get_android_manifest_activity_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const;
virtual String get_android_manifest_application_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const;
virtual String get_android_manifest_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const;
virtual PackedByteArray update_android_prebuilt_manifest(const Ref<EditorExportPlatform> &p_export_platform, const PackedByteArray &p_manifest_data) const;

Vector<String> get_ios_frameworks() const;
Vector<String> get_ios_embedded_frameworks() const;
Expand Down
36 changes: 27 additions & 9 deletions platform/android/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ void EditorExportPlatformAndroid::_fix_manifest(const Ref<EditorExportPreset> &p
ofs += size;
}

//create new andriodmanifest binary
// Create new android manifest binary.

Vector<uint8_t> ret;
ret.resize(string_table_begins + string_table.size() * 4);
Expand Down Expand Up @@ -1864,16 +1864,10 @@ String EditorExportPlatformAndroid::get_export_option_warning(const EditorExport
}
} else if (p_name == "gradle_build/use_gradle_build") {
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
String enabled_plugins_names = _get_plugins_names(Ref<EditorExportPreset>(p_preset));
if (!enabled_plugins_names.is_empty() && !gradle_build_enabled) {
String enabled_deprecated_plugins_names = _get_deprecated_plugins_names(Ref<EditorExportPreset>(p_preset));
if (!enabled_deprecated_plugins_names.is_empty() && !gradle_build_enabled) {
return TTR("\"Use Gradle Build\" must be enabled to use the plugins.");
}
} else if (p_name == "xr_features/xr_mode") {
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
int xr_mode_index = p_preset->get("xr_features/xr_mode");
if (xr_mode_index == XR_MODE_OPENXR && !gradle_build_enabled) {
return TTR("OpenXR requires \"Use Gradle Build\" to be enabled");
}
} else if (p_name == "gradle_build/compress_native_libraries") {
bool gradle_build_enabled = p_preset->get("gradle_build/use_gradle_build");
if (bool(p_preset->get("gradle_build/compress_native_libraries")) && !gradle_build_enabled) {
Expand Down Expand Up @@ -2599,6 +2593,7 @@ bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref<Edito
if (!dvalid) {
template_err += TTR("Custom debug template not found.") + "\n";
}
has_export_templates |= dvalid;
} else {
has_export_templates |= exists_export_template("android_debug.apk", &template_err);
}
Expand All @@ -2608,6 +2603,7 @@ bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref<Edito
if (!rvalid) {
template_err += TTR("Custom release template not found.") + "\n";
}
has_export_templates |= rvalid;
} else {
has_export_templates |= exists_export_template("android_release.apk", &template_err);
}
Expand Down Expand Up @@ -3151,6 +3147,17 @@ String EditorExportPlatformAndroid::join_abis(const Vector<EditorExportPlatformA
return ret;
}

String EditorExportPlatformAndroid::_get_deprecated_plugins_names(const Ref<EditorExportPreset> &p_preset) const {
Vector<String> names;

#ifndef DISABLE_DEPRECATED
PluginConfigAndroid::get_plugins_names(get_enabled_plugins(p_preset), names);
#endif // DISABLE_DEPRECATED

String plugins_names = String("|").join(names);
return plugins_names;
}

String EditorExportPlatformAndroid::_get_plugins_names(const Ref<EditorExportPreset> &p_preset) const {
Vector<String> names;

Expand Down Expand Up @@ -3655,6 +3662,17 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
//write
if (file == "AndroidManifest.xml") {
_fix_manifest(p_preset, data, p_give_internet);

// Allow editor export plugins to update the prebuilt manifest as needed.
Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
for (int i = 0; i < export_plugins.size(); i++) {
if (export_plugins[i]->supports_platform(Ref<EditorExportPlatform>(this))) {
PackedByteArray export_plugin_data = export_plugins[i]->update_android_prebuilt_manifest(Ref<EditorExportPlatform>(this), data);
if (!export_plugin_data.is_empty()) {
data = export_plugin_data;
}
}
}
}
if (file == "resources.arsc") {
_fix_resources(p_preset, data);
Expand Down
2 changes: 2 additions & 0 deletions platform/android/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;

String _get_deprecated_plugins_names(const Ref<EditorExportPreset> &p_preset) const;

String _get_plugins_names(const Ref<EditorExportPreset> &p_preset) const;

String _resolve_export_plugin_android_library_path(const String &p_android_library_path) const;
Expand Down

0 comments on commit 82c5a0f

Please sign in to comment.