Update the logic to load Godot Android plugins packaged into the binary.
The previous logic had the side effect of imposing a limit of one plugin per `aar` binary. The update lifts that restriction.
This commit is contained in:
parent
43e429fa93
commit
c5fb32d594
5 changed files with 8 additions and 66 deletions
|
@ -817,8 +817,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
|
||||||
|
|
||||||
manifest_text += _get_xr_features_tag(p_preset);
|
manifest_text += _get_xr_features_tag(p_preset);
|
||||||
manifest_text += _get_instrumentation_tag(p_preset);
|
manifest_text += _get_instrumentation_tag(p_preset);
|
||||||
String plugins_names = get_plugins_names(get_enabled_plugins(p_preset));
|
manifest_text += _get_application_tag(p_preset);
|
||||||
manifest_text += _get_application_tag(p_preset, plugins_names);
|
|
||||||
manifest_text += "</manifest>\n";
|
manifest_text += "</manifest>\n";
|
||||||
String manifest_path = vformat("res://android/build/src/%s/AndroidManifest.xml", (p_debug ? "debug" : "release"));
|
String manifest_path = vformat("res://android/build/src/%s/AndroidManifest.xml", (p_debug ? "debug" : "release"));
|
||||||
|
|
||||||
|
@ -869,8 +868,6 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
|
||||||
int xr_mode_index = p_preset->get("xr_features/xr_mode");
|
int xr_mode_index = p_preset->get("xr_features/xr_mode");
|
||||||
bool focus_awareness = p_preset->get("xr_features/focus_awareness");
|
bool focus_awareness = p_preset->get("xr_features/focus_awareness");
|
||||||
|
|
||||||
String plugins_names = get_plugins_names(get_enabled_plugins(p_preset));
|
|
||||||
|
|
||||||
Vector<String> perms;
|
Vector<String> perms;
|
||||||
// Write permissions into the perms variable.
|
// Write permissions into the perms variable.
|
||||||
_get_permissions(p_preset, p_give_internet, perms);
|
_get_permissions(p_preset, p_give_internet, perms);
|
||||||
|
@ -1024,11 +1021,6 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
|
||||||
encode_uint32(xr_mode_index == /* XRMode.OVR */ 1 && focus_awareness ? 0xFFFFFFFF : 0, &p_manifest.write[iofs + 16]);
|
encode_uint32(xr_mode_index == /* XRMode.OVR */ 1 && focus_awareness ? 0xFFFFFFFF : 0, &p_manifest.write[iofs + 16]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tname == "meta-data" && attrname == "value" && value == "plugins_value" && !plugins_names.empty()) {
|
|
||||||
// Update the meta-data 'android:value' attribute with the list of enabled plugins.
|
|
||||||
string_table.write[attr_value] = plugins_names;
|
|
||||||
}
|
|
||||||
|
|
||||||
is_focus_aware_metadata = tname == "meta-data" && attrname == "name" && value == "com.oculus.vr.focusaware";
|
is_focus_aware_metadata = tname == "meta-data" && attrname == "name" && value == "com.oculus.vr.focusaware";
|
||||||
iofs += 20;
|
iofs += 20;
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,14 +257,6 @@ String _get_instrumentation_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||||
return manifest_instrumentation_text;
|
return manifest_instrumentation_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _get_plugins_tag(const String &plugins_names) {
|
|
||||||
if (!plugins_names.empty()) {
|
|
||||||
return vformat(" <meta-data tools:node=\"replace\" android:name=\"plugins\" android:value=\"%s\" />\n", plugins_names);
|
|
||||||
} else {
|
|
||||||
return " <meta-data tools:node=\"remove\" android:name=\"plugins\" />\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
|
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||||
String orientation = _get_android_orientation_label(_get_screen_orientation());
|
String orientation = _get_android_orientation_label(_get_screen_orientation());
|
||||||
|
@ -283,7 +275,7 @@ String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||||
return manifest_activity_text;
|
return manifest_activity_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _get_application_tag(const Ref<EditorExportPreset> &p_preset, const String &plugins_names) {
|
String _get_application_tag(const Ref<EditorExportPreset> &p_preset) {
|
||||||
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
|
||||||
String manifest_application_text =
|
String manifest_application_text =
|
||||||
" <application android:label=\"@string/godot_project_name_string\"\n"
|
" <application android:label=\"@string/godot_project_name_string\"\n"
|
||||||
|
@ -291,7 +283,6 @@ String _get_application_tag(const Ref<EditorExportPreset> &p_preset, const Strin
|
||||||
" android:icon=\"@mipmap/icon\">\n\n"
|
" android:icon=\"@mipmap/icon\">\n\n"
|
||||||
" <meta-data tools:node=\"remove\" android:name=\"xr_mode_metadata_name\" />\n";
|
" <meta-data tools:node=\"remove\" android:name=\"xr_mode_metadata_name\" />\n";
|
||||||
|
|
||||||
manifest_application_text += _get_plugins_tag(plugins_names);
|
|
||||||
if (uses_xr) {
|
if (uses_xr) {
|
||||||
manifest_application_text += " <meta-data tools:node=\"replace\" android:name=\"com.samsung.android.vr.application.mode\" android:value=\"vr_only\" />\n";
|
manifest_application_text += " <meta-data tools:node=\"replace\" android:name=\"com.samsung.android.vr.application.mode\" android:value=\"vr_only\" />\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,6 @@
|
||||||
android:name="xr_mode_metadata_name"
|
android:name="xr_mode_metadata_name"
|
||||||
android:value="xr_mode_metadata_value" />
|
android:value="xr_mode_metadata_value" />
|
||||||
|
|
||||||
<!-- Metadata populated at export time and used by Godot to figure out which plugins must be enabled. -->
|
|
||||||
<meta-data
|
|
||||||
android:name="plugins"
|
|
||||||
android:value="plugins_value"/>
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".GodotApp"
|
android:name=".GodotApp"
|
||||||
android:label="@string/godot_project_name_string"
|
android:label="@string/godot_project_name_string"
|
||||||
|
|
|
@ -99,7 +99,7 @@ ext.getGodotLibraryVersion = { ->
|
||||||
return libraryVersion
|
return libraryVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
final String PLUGIN_VALUE_SEPARATOR_REGEX = "\\|"
|
final String VALUE_SEPARATOR_REGEX = "\\|"
|
||||||
|
|
||||||
// get the list of ABIs the project should be exported to
|
// get the list of ABIs the project should be exported to
|
||||||
ext.getExportEnabledABIs = { ->
|
ext.getExportEnabledABIs = { ->
|
||||||
|
@ -108,7 +108,7 @@ ext.getExportEnabledABIs = { ->
|
||||||
enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
|
enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
|
||||||
}
|
}
|
||||||
Set<String> exportAbiFilter = [];
|
Set<String> exportAbiFilter = [];
|
||||||
for (String abi_name : enabledABIs.split(PLUGIN_VALUE_SEPARATOR_REGEX)) {
|
for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
|
||||||
if (!abi_name.trim().isEmpty()){
|
if (!abi_name.trim().isEmpty()){
|
||||||
exportAbiFilter.add(abi_name);
|
exportAbiFilter.add(abi_name);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ ext.getGodotPluginsMavenRepos = { ->
|
||||||
if (project.hasProperty("plugins_maven_repos")) {
|
if (project.hasProperty("plugins_maven_repos")) {
|
||||||
String mavenReposProperty = project.property("plugins_maven_repos")
|
String mavenReposProperty = project.property("plugins_maven_repos")
|
||||||
if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
|
if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
|
||||||
for (String mavenRepoUrl : mavenReposProperty.split(PLUGIN_VALUE_SEPARATOR_REGEX)) {
|
for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
|
||||||
mavenRepos += mavenRepoUrl.trim()
|
mavenRepos += mavenRepoUrl.trim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ ext.getGodotPluginsRemoteBinaries = { ->
|
||||||
if (project.hasProperty("plugins_remote_binaries")) {
|
if (project.hasProperty("plugins_remote_binaries")) {
|
||||||
String remoteDepsList = project.property("plugins_remote_binaries")
|
String remoteDepsList = project.property("plugins_remote_binaries")
|
||||||
if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
|
if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
|
||||||
for (String dep: remoteDepsList.split(PLUGIN_VALUE_SEPARATOR_REGEX)) {
|
for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
|
||||||
remoteDeps += dep.trim()
|
remoteDeps += dep.trim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ ext.getGodotPluginsLocalBinaries = { ->
|
||||||
if (project.hasProperty("plugins_local_binaries")) {
|
if (project.hasProperty("plugins_local_binaries")) {
|
||||||
String pluginsList = project.property("plugins_local_binaries")
|
String pluginsList = project.property("plugins_local_binaries")
|
||||||
if (pluginsList != null && !pluginsList.trim().isEmpty()) {
|
if (pluginsList != null && !pluginsList.trim().isEmpty()) {
|
||||||
for (String plugin : pluginsList.split(PLUGIN_VALUE_SEPARATOR_REGEX)) {
|
for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
|
||||||
binDeps += plugin.trim()
|
binDeps += plugin.trim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,6 @@ import androidx.annotation.Nullable;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,13 +55,6 @@ public final class GodotPluginRegistry {
|
||||||
|
|
||||||
private static final String GODOT_PLUGIN_V1_NAME_PREFIX = "org.godotengine.plugin.v1.";
|
private static final String GODOT_PLUGIN_V1_NAME_PREFIX = "org.godotengine.plugin.v1.";
|
||||||
|
|
||||||
/**
|
|
||||||
* Name for the metadata containing the list of Godot plugins to enable.
|
|
||||||
*/
|
|
||||||
private static final String GODOT_ENABLED_PLUGINS_LABEL = "plugins";
|
|
||||||
|
|
||||||
private static final String PLUGIN_VALUE_SEPARATOR_REGEX = "\\|";
|
|
||||||
|
|
||||||
private static GodotPluginRegistry instance;
|
private static GodotPluginRegistry instance;
|
||||||
private final ConcurrentHashMap<String, GodotPlugin> registry;
|
private final ConcurrentHashMap<String, GodotPlugin> registry;
|
||||||
|
|
||||||
|
@ -133,37 +124,11 @@ public final class GodotPluginRegistry {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When using the Godot editor for building and exporting the apk, this is used to check
|
|
||||||
// which plugins to enable.
|
|
||||||
// When using a custom process to generate the apk, the metadata is not needed since
|
|
||||||
// it's assumed that the developer is aware of the dependencies included in the apk.
|
|
||||||
final Set<String> enabledPluginsSet;
|
|
||||||
if (metaData.containsKey(GODOT_ENABLED_PLUGINS_LABEL)) {
|
|
||||||
String enabledPlugins = metaData.getString(GODOT_ENABLED_PLUGINS_LABEL, "");
|
|
||||||
String[] enabledPluginsList = enabledPlugins.split(PLUGIN_VALUE_SEPARATOR_REGEX);
|
|
||||||
if (enabledPluginsList.length == 0) {
|
|
||||||
// No plugins to enable. Aborting early.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
enabledPluginsSet = new HashSet<>();
|
|
||||||
for (String enabledPlugin : enabledPluginsList) {
|
|
||||||
enabledPluginsSet.add(enabledPlugin.trim());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
enabledPluginsSet = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int godotPluginV1NamePrefixLength = GODOT_PLUGIN_V1_NAME_PREFIX.length();
|
int godotPluginV1NamePrefixLength = GODOT_PLUGIN_V1_NAME_PREFIX.length();
|
||||||
for (String metaDataName : metaData.keySet()) {
|
for (String metaDataName : metaData.keySet()) {
|
||||||
// Parse the meta-data looking for entry with the Godot plugin name prefix.
|
// Parse the meta-data looking for entry with the Godot plugin name prefix.
|
||||||
if (metaDataName.startsWith(GODOT_PLUGIN_V1_NAME_PREFIX)) {
|
if (metaDataName.startsWith(GODOT_PLUGIN_V1_NAME_PREFIX)) {
|
||||||
String pluginName = metaDataName.substring(godotPluginV1NamePrefixLength).trim();
|
String pluginName = metaDataName.substring(godotPluginV1NamePrefixLength).trim();
|
||||||
if (enabledPluginsSet != null && !enabledPluginsSet.contains(pluginName)) {
|
|
||||||
Log.w(TAG, "Plugin " + pluginName + " is listed in the dependencies but is not enabled.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.i(TAG, "Initializing Godot plugin " + pluginName);
|
Log.i(TAG, "Initializing Godot plugin " + pluginName);
|
||||||
|
|
||||||
// Retrieve the plugin class full name.
|
// Retrieve the plugin class full name.
|
||||||
|
@ -178,8 +143,7 @@ public final class GodotPluginRegistry {
|
||||||
.getConstructor(Godot.class);
|
.getConstructor(Godot.class);
|
||||||
GodotPlugin pluginHandle = pluginConstructor.newInstance(godot);
|
GodotPlugin pluginHandle = pluginConstructor.newInstance(godot);
|
||||||
|
|
||||||
// Load the plugin initializer into the registry using the plugin name
|
// Load the plugin initializer into the registry using the plugin name as key.
|
||||||
// as key.
|
|
||||||
if (!pluginName.equals(pluginHandle.getPluginName())) {
|
if (!pluginName.equals(pluginHandle.getPluginName())) {
|
||||||
Log.w(TAG,
|
Log.w(TAG,
|
||||||
"Meta-data plugin name does not match the value returned by the plugin handle: " + pluginName + " =/= " + pluginHandle.getPluginName());
|
"Meta-data plugin name does not match the value returned by the plugin handle: " + pluginName + " =/= " + pluginHandle.getPluginName());
|
||||||
|
|
Loading…
Reference in a new issue