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 Mar 8, 2025
1 parent b5bdb88 commit 64936fe
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 160 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 @@ -143,6 +143,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 @@ -174,6 +175,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
347 changes: 223 additions & 124 deletions platform/android/export/export_plugin.cpp

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion platform/android/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "godot_plugin_config.h"
#endif // DISABLE_DEPRECATED

#include "gradle_export_util.h"

#include "core/io/image.h"
#include "core/io/zip_io.h"
#include "core/os/os.h"
Expand Down Expand Up @@ -75,6 +77,12 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
EditorProgress *ep = nullptr;
};

struct FeatureInfo {
String name;
bool required;
String version = "";
};

#ifndef DISABLE_DEPRECATED
mutable Vector<PluginConfigAndroid> android_plugins;
mutable SafeFlag android_plugins_changed;
Expand Down Expand Up @@ -151,7 +159,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

bool _has_manage_external_storage_permission(const Vector<String> &p_permissions);

void _get_permissions(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions);
void _get_manifest_info(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions, Vector<FeatureInfo> &r_features, Vector<MetadataInfo> &r_metadata);

void _write_tmp_manifest(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, bool p_debug);

Expand Down Expand Up @@ -235,6 +243,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
6 changes: 5 additions & 1 deletion platform/android/export/gradle_export_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ String _get_activity_tag(const Ref<EditorExportPlatform> &p_export_platform, con
return manifest_activity_text;
}

String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_has_read_write_storage_permission, bool p_debug) {
String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_has_read_write_storage_permission, bool p_debug, const Vector<MetadataInfo> &p_metadata) {
int app_category_index = (int)(p_preset->get("package/app_category"));
bool is_game = app_category_index == APP_CATEGORY_GAME;

Expand All @@ -330,6 +330,10 @@ String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform,
}
manifest_application_text += " tools:ignore=\"GoogleAppIndexingWarning\">\n\n";

for (int i = 0; i < p_metadata.size(); i++) {
manifest_application_text += vformat(" <meta-data tools:node=\"replace\" android:name=\"%s\" android:value=\"%s\" />\n", p_metadata[i].name, p_metadata[i].value);
}

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(p_export_platform)) {
Expand Down
7 changes: 6 additions & 1 deletion platform/android/export/gradle_export_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ struct CustomExportData {
Vector<String> libs;
};

struct MetadataInfo {
String name;
String value;
};

int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation);

String _get_android_orientation_label(DisplayServer::ScreenOrientation screen_orientation);
Expand Down Expand Up @@ -105,4 +110,4 @@ String _get_screen_sizes_tag(const Ref<EditorExportPreset> &p_preset);

String _get_activity_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug);

String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_has_read_write_storage_permission, bool p_debug);
String _get_application_tag(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset, bool p_has_read_write_storage_permission, bool p_debug, const Vector<MetadataInfo> &p_metadata);
9 changes: 0 additions & 9 deletions platform/android/java/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
android:enabled="true"
tools:targetApi="29" />

<!-- Records the version of the Godot editor used for building -->
<meta-data
android:name="org.godotengine.editor.version"
android:value="${godotEditorVersion}" />
<!-- Records the rendering method used by the Godot engine -->
<meta-data
android:name="org.godotengine.rendering.method"
android:value="${godotRenderingMethod}"/>

<activity
android:name=".GodotApp"
android:label="@string/godot_project_name_string"
Expand Down
5 changes: 0 additions & 5 deletions platform/android/java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ android {
abiFilters export_abi_list
}

manifestPlaceholders = [
godotEditorVersion: getGodotEditorVersion(),
godotRenderingMethod: getGodotRenderingMethod()
]

// Feel free to modify the application id to your own.
applicationId getExportPackageName()
versionCode getExportVersionCode()
Expand Down
19 changes: 0 additions & 19 deletions platform/android/java/app/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,6 @@ ext.getExportTargetSdkVersion = { ->
}
}

ext.getGodotRenderingMethod = { ->
String renderingMethod = project.hasProperty("godot_rendering_method") ? project.property("godot_rendering_method") : ""
return renderingMethod
}

ext.getGodotEditorVersion = { ->
String editorVersion = project.hasProperty("godot_editor_version") ? project.property("godot_editor_version") : ""
if (editorVersion == null || editorVersion.isEmpty()) {
// Try the library version first
editorVersion = getGodotLibraryVersionName()

if (editorVersion.isEmpty()) {
// Fallback value.
editorVersion = "custom_build"
}
}
return editorVersion
}

ext.getGodotLibraryVersionCode = { ->
String versionName = ""
int versionCode = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
<!-- Enable passthrough background during the splash screen -->
<meta-data android:name="com.oculus.ossplash.background" android:value="passthrough-contextual"/>

<meta-data android:name="com.oculus.handtracking.version" android:value="V2.0" />

</application>

</manifest>

0 comments on commit 64936fe

Please sign in to comment.