Android plugin can't be found - I've tried everything

Godot Version

4.3

Question

Hey all, hopefully someone can spot where I am making a mistake. For the life of me, I have not been able to get my Godot app to be able to load and use an Android plugin.

I initially tried using the Godot Android Plugin Template (GitHub - m4gr3d/Godot-Android-Plugin-Template: This repository serves as a quickstart template for building a Godot Android plugin for Godot 4.2+.). That didn’t build properly on my machine, so I scrapped it.

Then I tried the following YouTube tutorial from FinePointCGI: https://www.youtube.com/watch?v=Vy9Nrbrr8H8

It all builds properly, but my app can’t find/load the plugin.

I also tried following the instructions in the documentation: Godot Android plugins — Godot Engine (stable) documentation in English

Those instructions are fairly close to the YouTube tutorial that I followed. Still no luck. I am not creating a complicated plugin. It’s just a simple hello world. Anyway, I’ll post some details below:

My Android library has a namespace of com.davidpruitt.godotandroidhelloworld. Within that namespace I have a single class called GodotAndroidPlugin. The plugin name is also GodotAndroidPlugin.

The plugin’s class looks like this:

public class GodotAndroidPlugin extends GodotPlugin
{
    /**
     * Base constructor passing a {@link Godot} instance through which the plugin can access Godot's
     * APIs and lifecycle events.
     *
     * @param godot
     */
    public GodotAndroidPlugin(Godot godot)
    {
        super(godot);
    }

    @NonNull
    @Override
    public String getPluginName()
    {
        return "GodotAndroidPlugin";
    }

    @UsedByGodot
    public void MakeToast()
    {
        getGodot().getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run()
            {
                Toast.makeText(getGodot().getActivity(), "Hello, World!", Toast.LENGTH_LONG).show();
            }
        });
    }

    @UsedByGodot
    public String GetFunAndroidString ()
    {
        return "Super-cali-fragilistic";
    }
}

I made the required changes in my AndroidManifest.xml file, so it looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application>
        <meta-data
            android:name="org.godotengine.plugin.v2.GodotAndroidPlugin"
            android:value="com.davidpruitt.godotpluginhelloworld.GodotAndroidPlugin" />
    </application>

</manifest>

My build.gradle is fairly standard with all the required changes:

plugins {
    id 'com.android.library'
}

android {
    namespace 'com.davidpruitt.godotpluginhelloworld'
    compileSdk 34

    defaultConfig {
        minSdk 24
        targetSdk 34
        versionCode 1
        versionName "1.0"

        buildConfigField("String", "GODOT_PLUGIN_NAME", "\"GodotAndroidPlugin\"")

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        buildConfig = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            buildConfigField("String", "pluginPackageName", "\"com.davidpruitt.godotpluginhelloworld\"")
            buildConfigField("String", "pluginName", "\"GodotAndroidPlugin\"")
        }
        debug {
            buildConfigField("String", "pluginPackageName", "\"com.davidpruitt.godotpluginhelloworld\"")
            buildConfigField("String", "pluginName", "\"GodotAndroidPlugin\"")
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
}

dependencies {

    implementation libs.appcompat
    implementation libs.material
    implementation libs.godot
    testImplementation libs.junit
    androidTestImplementation libs.ext.junit
    androidTestImplementation libs.espresso.core
}

I’ve also tried this without the buildConfigField and buildFeatures entries. I’ve also tried this with JavaVersion.VERSION_1_8 (the default). No luck either way.

Currently I am importing the “org.godotengine:godot:4.3.0.stable” dependency, but I have also tried it with “org.godotengine:godot:4.2.0.stable” dependency. No luck either way.

In the build.gradle file that I show above, I used the Android Studio IDE to add the dependency (Navigating to “File > Project Structure > Dependencies” while inside of Android Studio and then adding the dependency) - so the actual dependency is in a TOML file, but I have also tried inserting the string “org.godotengine:godot:4.2.0.stable” directly into the build.gradle. No luck either way.

Within the Godot project structure, I have the plugin located at “addons/GodotAndroidPlugin”. I added the plugin by navigating to the Project Settings > Plugins in the Godot IDE. I then copied/pasted the AAR file into that folder. The script that loads the plugin looks like the following (pretty much identical to the code on Godot’s documentation page):

@tool
extends EditorPlugin

# A class member to hold the editor export plugin during its lifecycle.
var export_plugin : AndroidExportPlugin

func _enter_tree():
	# Initialization of the plugin goes here.
	export_plugin = AndroidExportPlugin.new()
	add_export_plugin(export_plugin)


func _exit_tree():
	# Clean-up of the plugin goes here.
	remove_export_plugin(export_plugin)
	export_plugin = null


class AndroidExportPlugin extends EditorExportPlugin:
	# Plugin's name.
	var _plugin_name = "GodotAndroidPlugin"

	# Specifies which platform is supported by the plugin.
	func _supports_platform(platform):
		if platform is EditorExportPlatformAndroid:
			return true
		return false

	# Return the paths of the plugin's AAR binaries relative to the 'addons' directory.
	func _get_android_libraries(platform, debug):
		if debug:
			return PackedStringArray(["GodotAndroidPlugin/app-debug.aar"])
		else:
			return PackedStringArray(["GodotAndroidPlugin/app-debug.aar"])

	# Return the plugin's name.
	func _get_name():
		return _plugin_name

Finally, my main application code looks like this:

class_name Main
extends Node2D

@onready var ui_label := $CanvasLayer/VFlowContainer/Label

var plugin

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	if (Engine.has_singleton("GodotAndroidPlugin")):
		plugin = Engine.get_singleton("GodotAndroidPlugin")
		print_debug("Yay it worked!")
	else:
		if (ui_label):
			ui_label.text = "Cannot find plugin :("
		print_debug("Cannot find plugin!")


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass


func _on_button_pressed() -> void:
	if (plugin):
		print_debug("Yay it worked!")
		plugin.MakeToast()
		var mystr: String = plugin.GetFunAndroidString()
		ui_label.text = mystr
	else:
		ui_label.text = "Cannot find plugin :("

Everything, both the Android project as well as the Godot project, can be found at the following Github link:

Seriously, nothing that I have tried works. It always fails to load/find the plugin.

Any help would be appreciated!!! Thank you!!!

Hello,
I also tried the online examples, but I couldn’t get them to work. I had to create the Android app as a library module and make some additional changes for it to work. I’ve created a video tutorial about this (if you’re interested: Create an Android Plugin for Godot 4.3 with C# and Java) in the hopes that it might help others who encounter similar issues.

The Godot plugin definition is in C#, but I think you can extrapolate it to GDScript. If you run into any issues, feel free to let me know, and I’ll try to help.