Search code examples
javaandroidgoogle-play-gamescapacitorcapacitor-plugin

Capacitor plugin doesn't pass arguments to java


I'm using this plugin to implement Google Play Games Services in an Ionic React/Capacitor project.

However, when I call GameServices.showLeaderboard("abcdefghijklmnopqr");, logcat show the following:

05-09 07:44:51.544 15437 15524 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 129018517, pluginId: GameServices, methodName: showLeaderboard
05-09 07:44:51.544 15437 15524 V Capacitor: callback: 129018517, pluginId: GameServices, methodName: showLeaderboard, methodData: {}
05-09 07:44:51.545 15437 15502 W GameServices: showLeaderboard called without providing leaderboardId

As you can see, the methodData is empty.

I have absolutely no idea of java (hence why I use Capacitor), but this is the only piece of code I could find that looks remotely related, in android\src\main\java\GameServices.java, in the GitHub linked.

@PluginMethod()
    public void showLeaderboard(final PluginCall call) {
        final String leaderboardId = call.getString("leaderboardId");
        if (leaderboardId == null) {
            Log.w(TAG, "showLeaderboard called without providing leaderboardId");
            return;
        }
        Log.d(TAG, "showLeaderboard called with id: " + leaderboardId);

        final GoogleSignInAccount lastSignedInAccount = GoogleSignIn.getLastSignedInAccount(getContext());
        if (null == lastSignedInAccount) {
            Log.w(TAG,
                    "cannot find last signed in account, either services are disabled or fingerprint doesn't match services account");
            call.resolve();
            return;
        }

        Games.getLeaderboardsClient(getContext(), lastSignedInAccount).getLeaderboardIntent(leaderboardId)
                .addOnCompleteListener(task -> {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "showLeaderboard:getIntent:success");
                        saveCall(call);
                        startActivityForResult(call, task.getResult(), RC_LEADERBOARD_UI);
                    } else {
                        Log.e(TAG, "showLeaderboard:getIntent:error");
                        call.reject("showLeaderboard:getIntent:error");
                    }
                });
    }

Could you please help me work around this issue? It seems to be the only Google Play Games Capacitor plugin that remotely works...

Edit 1: I should note, that the GameServices.signIn(); method works just fine.

Edit2: Trying to call GameServices.unlockAchievement("abcdef"); didn't work either, logging Achievement ID must not be null or empty. Apparently no method, that needs an argument, works.


Solution

  • After rifling through all of the plugins code, I realized the methods expect objects as parameters.

    This works:

    GameServices.showLeaderboard({leaderboardId: "abcdefghijklmnopqr"});