mirror of
https://github.com/godotengine/godot.git
synced 2025-10-31 21:51:22 +00:00
Implementation of the Godot Android Plugin configuration file
This commit is contained in:
parent
163687d17a
commit
14e6696c8e
11 changed files with 534 additions and 54 deletions
|
|
@ -32,8 +32,8 @@
|
|||
|
||||
<!-- Metadata populated at export time and used by Godot to figure out which plugins must be enabled. -->
|
||||
<meta-data
|
||||
android:name="custom_template_plugins"
|
||||
android:value="custom_template_plugins_value"/>
|
||||
android:name="plugins"
|
||||
android:value="plugins_value"/>
|
||||
|
||||
<activity
|
||||
android:name=".GodotApp"
|
||||
|
|
|
|||
|
|
@ -21,6 +21,16 @@ allprojects {
|
|||
mavenCentral()
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
// Godot user plugins custom maven repos
|
||||
String[] mavenRepos = getGodotPluginsMavenRepos()
|
||||
if (mavenRepos != null && mavenRepos.size() > 0) {
|
||||
for (String repoUrl : mavenRepos) {
|
||||
maven {
|
||||
url repoUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,15 +50,18 @@ dependencies {
|
|||
releaseImplementation fileTree(dir: 'libs/release', include: ['*.jar', '*.aar'])
|
||||
}
|
||||
|
||||
// Godot prebuilt plugins
|
||||
implementation fileTree(dir: 'libs/plugins', include: ["GodotPayment*.aar"])
|
||||
// Godot user plugins remote dependencies
|
||||
String[] remoteDeps = getGodotPluginsRemoteBinaries()
|
||||
if (remoteDeps != null && remoteDeps.size() > 0) {
|
||||
for (String dep : remoteDeps) {
|
||||
implementation dep
|
||||
}
|
||||
}
|
||||
|
||||
// Godot user plugins dependencies
|
||||
String pluginsDir = getGodotPluginsDirectory()
|
||||
String[] pluginsBinaries = getGodotPluginsBinaries()
|
||||
if (pluginsDir != null && !pluginsDir.isEmpty() &&
|
||||
pluginsBinaries != null && pluginsBinaries.size() > 0) {
|
||||
implementation fileTree(dir: pluginsDir, include: pluginsBinaries)
|
||||
// Godot user plugins local dependencies
|
||||
String[] pluginsBinaries = getGodotPluginsLocalBinaries()
|
||||
if (pluginsBinaries != null && pluginsBinaries.size() > 0) {
|
||||
implementation files(pluginsBinaries)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,39 +28,68 @@ ext.getExportPackageName = { ->
|
|||
return appId
|
||||
}
|
||||
|
||||
final String PLUGIN_VALUE_SEPARATOR_REGEX = "\\|"
|
||||
|
||||
/**
|
||||
* Parse the project properties for the 'custom_template_plugins' property and return
|
||||
* Parse the project properties for the 'plugins_maven_repos' property and return the list
|
||||
* of maven repos.
|
||||
*/
|
||||
ext.getGodotPluginsMavenRepos = { ->
|
||||
Set<String> mavenRepos = []
|
||||
|
||||
// Retrieve the list of maven repos.
|
||||
if (project.hasProperty("plugins_maven_repos")) {
|
||||
String mavenReposProperty = project.property("plugins_maven_repos")
|
||||
if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
|
||||
for (String mavenRepoUrl : mavenReposProperty.split(PLUGIN_VALUE_SEPARATOR_REGEX)) {
|
||||
mavenRepos += mavenRepoUrl.trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mavenRepos
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the project properties for the 'plugins_remote_binaries' property and return
|
||||
* it for inclusion in the build dependencies.
|
||||
*/
|
||||
ext.getGodotPluginsRemoteBinaries = { ->
|
||||
Set<String> remoteDeps = []
|
||||
|
||||
// Retrieve the list of remote plugins binaries.
|
||||
if (project.hasProperty("plugins_remote_binaries")) {
|
||||
String remoteDepsList = project.property("plugins_remote_binaries")
|
||||
if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
|
||||
for (String dep: remoteDepsList.split(PLUGIN_VALUE_SEPARATOR_REGEX)) {
|
||||
remoteDeps += dep.trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
return remoteDeps
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the project properties for the 'plugins_local_binaries' property and return
|
||||
* their binaries for inclusion in the build dependencies.
|
||||
*
|
||||
* The listed plugins must have their binaries in the project plugins directory.
|
||||
* Returns the prebuilt plugins if the 'plugins_local_binaries' property is unavailable.
|
||||
*/
|
||||
ext.getGodotPluginsBinaries = { ->
|
||||
String[] binDeps = []
|
||||
ext.getGodotPluginsLocalBinaries = { ->
|
||||
// Set the prebuilt plugins as default. If custom build is enabled,
|
||||
// the 'plugins_local_binaries' will be defined so we can use it instead.
|
||||
Set<String> binDeps = ["libs/plugins/GodotPayment.release.aar"]
|
||||
|
||||
// Retrieve the list of enabled plugins.
|
||||
if (project.hasProperty("custom_template_plugins")) {
|
||||
String pluginsList = project.property("custom_template_plugins")
|
||||
// Retrieve the list of local plugins binaries.
|
||||
if (project.hasProperty("plugins_local_binaries")) {
|
||||
binDeps.clear()
|
||||
String pluginsList = project.property("plugins_local_binaries")
|
||||
if (pluginsList != null && !pluginsList.trim().isEmpty()) {
|
||||
for (String plugin : pluginsList.split(",")) {
|
||||
binDeps += plugin.trim() + "*.aar"
|
||||
for (String plugin : pluginsList.split(PLUGIN_VALUE_SEPARATOR_REGEX)) {
|
||||
binDeps += plugin.trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return binDeps
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the project properties for the 'custom_template_plugins_dir' property and return
|
||||
* its value.
|
||||
*
|
||||
* The returned value is the directory containing user plugins.
|
||||
*/
|
||||
ext.getGodotPluginsDirectory = { ->
|
||||
// The plugins directory is provided by the 'custom_template_plugins_dir' property.
|
||||
String pluginsDir = project.hasProperty("custom_template_plugins_dir")
|
||||
? project.property("custom_template_plugins_dir")
|
||||
: ""
|
||||
|
||||
return pluginsDir
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ task generateGodotTemplates(type: GradleBuild) {
|
|||
startParameter.excludedTaskNames += ":lib:" + getSconsTaskName(buildType)
|
||||
}
|
||||
|
||||
tasks = ["copyGodotPaymentPluginToAppModule"]
|
||||
tasks = []
|
||||
|
||||
// Only build the apks and aar files for which we have native shared libraries.
|
||||
for (String target : supportedTargets) {
|
||||
|
|
@ -161,6 +161,7 @@ task generateGodotTemplates(type: GradleBuild) {
|
|||
}
|
||||
}
|
||||
|
||||
dependsOn 'copyGodotPaymentPluginToAppModule'
|
||||
finalizedBy 'zipCustomBuild'
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,9 @@ public final class GodotPluginRegistry {
|
|||
/**
|
||||
* Name for the metadata containing the list of Godot plugins to enable.
|
||||
*/
|
||||
private static final String GODOT_ENABLED_PLUGINS_LABEL = "custom_template_plugins";
|
||||
private static final String GODOT_ENABLED_PLUGINS_LABEL = "plugins";
|
||||
|
||||
private static final String PLUGIN_VALUE_SEPARATOR_REGEX = "\\|";
|
||||
|
||||
private static GodotPluginRegistry instance;
|
||||
private final ConcurrentHashMap<String, GodotPlugin> registry;
|
||||
|
|
@ -128,13 +130,13 @@ public final class GodotPluginRegistry {
|
|||
}
|
||||
|
||||
// When using the Godot editor for building and exporting the apk, this is used to check
|
||||
// which plugins to enable since the custom build template may contain prebuilt plugins.
|
||||
// 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(",");
|
||||
String[] enabledPluginsList = enabledPlugins.split(PLUGIN_VALUE_SEPARATOR_REGEX);
|
||||
if (enabledPluginsList.length == 0) {
|
||||
// No plugins to enable. Aborting early.
|
||||
return;
|
||||
|
|
@ -158,6 +160,8 @@ public final class GodotPluginRegistry {
|
|||
continue;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Initializing Godot plugin " + pluginName);
|
||||
|
||||
// Retrieve the plugin class full name.
|
||||
String pluginHandleClassFullName = metaData.getString(metaDataName);
|
||||
if (!TextUtils.isEmpty(pluginHandleClassFullName)) {
|
||||
|
|
@ -177,6 +181,7 @@ public final class GodotPluginRegistry {
|
|||
"Meta-data plugin name does not match the value returned by the plugin handle: " + pluginName + " =/= " + pluginHandle.getPluginName());
|
||||
}
|
||||
registry.put(pluginName, pluginHandle);
|
||||
Log.i(TAG, "Completed initialization for Godot plugin " + pluginHandle.getPluginName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.w(TAG, "Unable to load Godot plugin " + pluginName, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue