mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 21:51:22 +00:00 
			
		
		
		
	Relax restriction on loading v1 Android plugins on Godot 4.2+
This commit is contained in:
		
							parent
							
								
									0a7f75ec7b
								
							
						
					
					
						commit
						12d96eeaef
					
				
					 2 changed files with 46 additions and 19 deletions
				
			
		|  | @ -61,12 +61,15 @@ import javax.microedition.khronos.opengles.GL10; | ||||||
|  * <p> |  * <p> | ||||||
|  * A Godot Android plugin is an Android library with the following requirements: |  * A Godot Android plugin is an Android library with the following requirements: | ||||||
|  * <p> |  * <p> | ||||||
|  * - The library must have a 'compileOnly' dependency on the Godot Android library: `compileOnly "org.godotengine:godot:<godotLibVersion>"` |  * - The plugin must have a dependency on the Godot Android library: `implementation "org.godotengine:godot:<godotLibVersion>"` | ||||||
|  * <p> |  * <p> | ||||||
|  * - The library must include a <meta-data> tag in its Android manifest with the following format: |  * - The plugin must include a <meta-data> tag in its Android manifest with the following format: | ||||||
|  * <meta-data android:name="org.godotengine.plugin.v2.[PluginName]" android:value="[plugin.init.ClassFullName]" /> |  * <meta-data android:name="org.godotengine.plugin.v2.[PluginName]" android:value="[plugin.init.ClassFullName]" /> | ||||||
|  |  * <p> | ||||||
|  * Where: |  * Where: | ||||||
|  |  * <p> | ||||||
|  * - 'PluginName' is the name of the plugin. |  * - 'PluginName' is the name of the plugin. | ||||||
|  |  * <p> | ||||||
|  * - 'plugin.init.ClassFullName' is the full name (package + class name) of the plugin init class |  * - 'plugin.init.ClassFullName' is the full name (package + class name) of the plugin init class | ||||||
|  * extending {@link GodotPlugin}. |  * extending {@link GodotPlugin}. | ||||||
|  * <p> |  * <p> | ||||||
|  | @ -83,6 +86,10 @@ public abstract class GodotPlugin { | ||||||
| 	private final Godot godot; | 	private final Godot godot; | ||||||
| 	private final ConcurrentHashMap<String, SignalInfo> registeredSignals = new ConcurrentHashMap<>(); | 	private final ConcurrentHashMap<String, SignalInfo> registeredSignals = new ConcurrentHashMap<>(); | ||||||
| 
 | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Base constructor passing a {@link Godot} instance through which the plugin can access Godot's | ||||||
|  | 	 * APIs and lifecycle events. | ||||||
|  | 	 */ | ||||||
| 	public GodotPlugin(Godot godot) { | 	public GodotPlugin(Godot godot) { | ||||||
| 		this.godot = godot; | 		this.godot = godot; | ||||||
| 	} | 	} | ||||||
|  | @ -109,11 +116,11 @@ public abstract class GodotPlugin { | ||||||
| 	 */ | 	 */ | ||||||
| 	public final void onRegisterPluginWithGodotNative() { | 	public final void onRegisterPluginWithGodotNative() { | ||||||
| 		registeredSignals.putAll( | 		registeredSignals.putAll( | ||||||
| 				registerPluginWithGodotNative(this, getPluginName(), getPluginSignals())); | 				registerPluginWithGodotNative(this, getPluginName(), getPluginMethods(), getPluginSignals())); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private static Map<String, SignalInfo> registerPluginWithGodotNative(Object pluginObject, | 	private static Map<String, SignalInfo> registerPluginWithGodotNative(Object pluginObject, | ||||||
| 			String pluginName, Set<SignalInfo> pluginSignals) { | 			String pluginName, List<String> pluginMethods, Set<SignalInfo> pluginSignals) { | ||||||
| 		nativeRegisterSingleton(pluginName, pluginObject); | 		nativeRegisterSingleton(pluginName, pluginObject); | ||||||
| 
 | 
 | ||||||
| 		Set<Method> filteredMethods = new HashSet<>(); | 		Set<Method> filteredMethods = new HashSet<>(); | ||||||
|  | @ -124,6 +131,14 @@ public abstract class GodotPlugin { | ||||||
| 			// Check if the method is annotated with {@link UsedByGodot}. | 			// Check if the method is annotated with {@link UsedByGodot}. | ||||||
| 			if (method.getAnnotation(UsedByGodot.class) != null) { | 			if (method.getAnnotation(UsedByGodot.class) != null) { | ||||||
| 				filteredMethods.add(method); | 				filteredMethods.add(method); | ||||||
|  | 			} else { | ||||||
|  | 				// For backward compatibility, process the methods from the given <pluginMethods> argument. | ||||||
|  | 				for (String methodName : pluginMethods) { | ||||||
|  | 					if (methodName.equals(method.getName())) { | ||||||
|  | 						filteredMethods.add(method); | ||||||
|  | 						break; | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | @ -260,6 +275,17 @@ public abstract class GodotPlugin { | ||||||
| 	@NonNull | 	@NonNull | ||||||
| 	public abstract String getPluginName(); | 	public abstract String getPluginName(); | ||||||
| 
 | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Returns the list of methods to be exposed to Godot. | ||||||
|  | 	 * | ||||||
|  | 	 * @deprecated Use the {@link UsedByGodot} annotation instead. | ||||||
|  | 	 */ | ||||||
|  | 	@NonNull | ||||||
|  | 	@Deprecated | ||||||
|  | 	public List<String> getPluginMethods() { | ||||||
|  | 		return Collections.emptyList(); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	/** | 	/** | ||||||
| 	 * Returns the list of signals to be exposed to Godot. | 	 * Returns the list of signals to be exposed to Godot. | ||||||
| 	 */ | 	 */ | ||||||
|  |  | ||||||
|  | @ -53,11 +53,11 @@ public final class GodotPluginRegistry { | ||||||
| 	private static final String TAG = GodotPluginRegistry.class.getSimpleName(); | 	private static final String TAG = GodotPluginRegistry.class.getSimpleName(); | ||||||
| 
 | 
 | ||||||
| 	/** | 	/** | ||||||
| 	 * Prefix used for version 1 of the Godot plugin, compatible with Godot 3.x | 	 * Prefix used for version 1 of the Godot plugin, mostly compatible with Godot 3.x | ||||||
| 	 */ | 	 */ | ||||||
| 	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."; | ||||||
| 	/** | 	/** | ||||||
| 	 * Prefix used for version 2 of the Godot plugin, compatible with Godot 4.x | 	 * Prefix used for version 2 of the Godot plugin, compatible with Godot 4.2+ | ||||||
| 	 */ | 	 */ | ||||||
| 	private static final String GODOT_PLUGIN_V2_NAME_PREFIX = "org.godotengine.plugin.v2."; | 	private static final String GODOT_PLUGIN_V2_NAME_PREFIX = "org.godotengine.plugin.v2."; | ||||||
| 
 | 
 | ||||||
|  | @ -130,12 +130,18 @@ public final class GodotPluginRegistry { | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			int godotPluginV2NamePrefixLength = GODOT_PLUGIN_V2_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. | ||||||
|  | 				String pluginName = null; | ||||||
| 				if (metaDataName.startsWith(GODOT_PLUGIN_V2_NAME_PREFIX)) { | 				if (metaDataName.startsWith(GODOT_PLUGIN_V2_NAME_PREFIX)) { | ||||||
| 					String pluginName = metaDataName.substring(godotPluginV2NamePrefixLength).trim(); | 					pluginName = metaDataName.substring(GODOT_PLUGIN_V2_NAME_PREFIX.length()).trim(); | ||||||
| 					Log.i(TAG, "Initializing Godot v2 plugin " + pluginName); | 				} else if (metaDataName.startsWith(GODOT_PLUGIN_V1_NAME_PREFIX)) { | ||||||
|  | 					pluginName = metaDataName.substring(GODOT_PLUGIN_V1_NAME_PREFIX.length()).trim(); | ||||||
|  | 					Log.w(TAG, "Godot v1 plugin are deprecated in Godot 4.2 and higher: " + pluginName); | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				if (!TextUtils.isEmpty(pluginName)) { | ||||||
|  | 					Log.i(TAG, "Initializing Godot plugin " + pluginName); | ||||||
| 
 | 
 | ||||||
| 					// Retrieve the plugin class full name. | 					// Retrieve the plugin class full name. | ||||||
| 					String pluginHandleClassFullName = metaData.getString(metaDataName); | 					String pluginHandleClassFullName = metaData.getString(metaDataName); | ||||||
|  | @ -155,22 +161,17 @@ public final class GodotPluginRegistry { | ||||||
| 										"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()); | ||||||
| 							} | 							} | ||||||
| 							registry.put(pluginName, pluginHandle); | 							registry.put(pluginName, pluginHandle); | ||||||
| 							Log.i(TAG, "Completed initialization for Godot v2 plugin " + pluginHandle.getPluginName()); | 							Log.i(TAG, "Completed initialization for Godot plugin " + pluginHandle.getPluginName()); | ||||||
| 						} catch (ClassNotFoundException | IllegalAccessException | | 						} catch (Exception e) { | ||||||
| 								InstantiationException | NoSuchMethodException | | 							Log.w(TAG, "Unable to load Godot plugin " + pluginName, e); | ||||||
| 								InvocationTargetException e) { |  | ||||||
| 							Log.w(TAG, "Unable to load Godot v2 plugin " + pluginName, e); |  | ||||||
| 						} | 						} | ||||||
| 					} else { | 					} else { | ||||||
| 						Log.w(TAG, "Invalid plugin loader class for " + pluginName); | 						Log.w(TAG, "Invalid plugin loader class for " + pluginName); | ||||||
| 					} | 					} | ||||||
| 				} else if (metaDataName.startsWith(GODOT_PLUGIN_V1_NAME_PREFIX)) { |  | ||||||
| 					String v1PluginName = metaDataName.substring(GODOT_PLUGIN_V1_NAME_PREFIX.length()).trim(); |  | ||||||
| 					Log.w(TAG, "Godot 4 does not support Godot 3 (v1) plugin: " + v1PluginName); |  | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} catch (PackageManager.NameNotFoundException e) { | 		} catch (Exception e) { | ||||||
| 			Log.e(TAG, "Unable load Godot Android v2 plugins from the manifest file.", e); | 			Log.e(TAG, "Unable load Godot Android plugins from the manifest file.", e); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Fredia Huya-Kouadio
						Fredia Huya-Kouadio