Creating Android plugins
Mobile gaming monetization is one such example since it requires features and capabilities that don’t belong to the core feature set of a game engine:
Analytics
In-app purchases
Receipt validation
Install tracking
Ads
Video ads
Cross-promotion
In-game soft & hard currencies
Promo codes
Login
Cloud saves
Leaderboards and scores
User support & feedback
Posting to Facebook, Twitter, etc.
Push notifications
While introduced in Godot 3.2, the Android plugin system got a significant architecture update starting with Godot 3.2.2. The new plugin system is backward-incompatible with the previous one, but both systems are kept functional in future releases of the 3.2.x branch. Since we previously did not version the Android plugin systems, the new one is now labelled and is the starting point for the modern Godot Android ecosystem.
Note: In Godot 4.0, the previous system will be fully deprecated and removed.
At its core, a Godot Android plugin is a Android archive library (aar archive file) with the following caveats:
The library must have a dependency on the Godot engine library (
godot-lib.<version>.<status>.aar
). A stable version is made available for each Godot release on the .The library must include a specifically configured
<meta-data>
tag in its manifest file.
Prerequisite: is strongly recommended as the IDE to use to create Android plugins. The instructions below assumes that you’re using Android Studio.
Follow these instructions to create an Android library module for your plugin.
Add the Godot engine library as a dependency to your plugin module:
Create a new class in the plugin module and make sure it extends
org.godotengine.godot.plugin.GodotPlugin
. At runtime, it will be used to instantiate a singleton object that will be used by the Godot engine to load, initialize and run the plugin.Update the plugin
AndroidManifest.xml
file:
Add the remaining logic for your plugin and run the
gradlew build
command to generate the plugin’saar
file. The build will likely generate both adebug
andrelease
aar
files. Depending on your need, pick only one version (usually the one) which to provide your users with.It’s recommended that the
aar
filename matches the following pattern:[PluginName]*.aar
wherePluginName
is the name of the plugin in PascalCase (e.g.:GodotPayment.release.aar
).Create a Godot Android Plugin configuration file to help the system detect and load your plugin:
Move the plugin configuration file (e.g.: MyPlugin.gdap
) and, if any, its local binary (e.g.: MyPlugin.aar
) and dependencies to the Godot project’s res://android/plugins
directory.
The Godot editor will automatically parse all .gdap
files in the directory and show a list of detected and toggleable plugins in the Android export presets window under the Plugins section.
From your script:
An Android plugin can define and provide C/C++ GDNative resources, either to provide and/or access functionality from the game logic. The GDNative resources can be bundled within the plugin aar
file which simplifies the distribution and deployment process:
The shared libraries (
.so
) for the defined GDNative libraries will be automatically bundled by theaar
build system.Godot
*.gdnlib
and*.gdns
resource files must be manually defined in the pluginassets
directory. The recommended path for these resources relative to theassets
directory should be:godot/plugin/v1/[PluginName]/
.
For GDNative libraries, the plugin singleton object must override the org.godotengine.godot.plugin.GodotPlugin::getPluginGDNativeLibrariesPaths()
method, and return the paths to the bundled GDNative libraries config files (*.gdnlib
). The paths must be relative to the assets
directory. At runtime, the plugin will provide these paths to Godot core which will use them to load and initialize the bundled GDNative libraries.
Check adb logcat
for possible problems, then:
More complex datatypes are not supported for now.