Using Android Plugin: Nonexistent function 'getPluginName' in base 'JNISingleton'

Viewed 137

Godot version: 3.2.3

Issue description: I am new at using Android Plugins in Godot, so I created this simple plugin with only one method.

public class GodotProva extends GodotPlugin
{
    public GodotProva(Godot godot) {
        super(godot);
    }

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

I tried to use it in Godot, with the following code:

func _pressed():
    if Engine.has_singleton("mylibrary"):
        var singleton = Engine.get_singleton("mylibrary")
                print(singleton.getPluginName())

I created an apk and installed it on my Android device. The problem is that when I press the button (and the function _pressed() is called), I can see from the logcat the error Nonexistent function 'getPluginName' in base 'JNISingleton'

I am sure that the plugin is found, because the "singleton" variable is not null. What am I doing wrong?

2 Answers

I found out that in Godot I can only call custom functions. The methods of the class GodotPlugin (such as getPluginName, getPluginMethods...) cannot be directly called.

In my case, I needed to define methods in getPluginMethods in my GodotPlugin like this:

    public void firstMethod() {
        // TODO
    }

    public void secondMethod() {
        // TODO
    }

    @SuppressWarnings("deprecation")
    @NonNull
    @Override
    public List<String> getPluginMethods() {
        return Arrays.asList("firstMethod", "secondMethod");
    }

I don't know why this case is not documented, but I wasted a lot of time on this and I think it would be useful for other people...

Related