While introduced in Godot 3.2.0, 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 and in Godot 4.0, the previous system was fully deprecated and removed.
Since we previously did not version the Android plugin systems, the new one is now labelled v1 and is the starting point for the modern Godot Android ecosystem.

Follow these instructions to add
the Godot engine library as a dependency for your plugin.

In the plugin module’s build.gradle file, replace implementation with compileOnly for the dependency line for the Godot engine library.

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.

Where PluginName is the name of the plugin, and plugin.init.ClassFullName is the full name (package + class name) of the plugin loading class.

Add the remaining logic for your plugin and run the gradlewbuild command to generate the plugin’s aar file.
The build will likely generate both a debug and releaseaar files.
Depending on your need, pick only one version (usually the release one) which to provide your users with.

It’s recommended that the aar filename matches the following pattern: [PluginName]*.aar where PluginName 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:

binary_type: can be either local or remote. The type affects the binary field

binary:

if binary_type is local, then this should be the filepath of the plugin aar file.

The filepath can be relative (e.g.: MyPlugin.aar) in which case it’s relative to the res://android/plugins directory.

The filepath can be absolute: res://some_path/MyPlugin.aar.

if binary_type is remote, then this should be a declaration for a remote gradle binary (e.g.: org.godot.example:my-plugin:0.0.0).

The dependencies section and fields are optional and defined as follow:

local: contains a list of filepaths to the local .aar binary files the plugin depends on. Similarly to the binary field (when the binary_type is local), the local binaries’ filepaths can be relative or absolute.

remote: contains a list of remote binary gradle dependencies for the plugin.

custom_maven_repos: contains a list of URLs specifying the custom maven repositories required for the plugin’s dependencies

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 res://android/plugins directory and show a list of detected and toggleable plugins in the Android export presets window under the Plugins section.

A 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 the aar build system.

Godot *.gdnlib and *.gdns resource files must be manually defined in the plugin assets directory.
The recommended path for these resources relative to the assets 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.