Issue with C++ client on Android

Hi,

In the last few days I’ve upgraded my app from Cocos2d to Axmol (a cocos2dx 4.0 clone). Great clone with lots of improvements, ongoing support and regular updates. All versions of my app (iOS, Mac, Windows, Android) use the exact same code.

On iOS and Mac all works wonderfull with Nakama. I can call a custom RPC on the Nakama server with a JSON payload and it works. I can get the leaderboards and it works. Authentication etc. also works fine.

On Android I however encounter strange issues: the app authenticates properly. Client is created. RtClient as well. But when the RPC is called the payload on the server side is completely garbled (seems like random data). Exact same call on iOS/Mac works fine. Checked the call in the debugger and the payload is perfectly formatted JSON; checked on the server: random/empty data in the payload

Syslog with a dump of payload on the Nakama server shows:

Jan  4 20:51:47 nakama nakama[33257]: {"level":"info","ts":"2023-01-04T20:51:47.421+0100","caller":"server/session_ws.go:81","msg":"New WebSocket session connected","uid":"9fbd0f4f-1c4f-4878-837b-64a2628f9556","sid":"39019f78-8c69-11ed-8af2-55826b6d133b","format":1}
Jan  4 20:51:47 nakama nakama[33257]: {"level":"info","ts":"2023-01-04T20:51:47.530+0100","caller":"server/runtime_lua_nakama.go:1733","msg":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000m�Kt\u0000\u0000�\u0001��8s\u0000\u0000\u0000`=��s\u0000\u0000�\u0001\u0000\u0000\u0000t\u0000\u0000��a�Fs\u0000\u0000\u0000P�}8s\u0000\u0000\u0000\u0000p�Fs\u0000\u0000\u0000�ꬻt\u0000\u0000��V�+t","runtime":"lua"}
Jan  4 20:51:47 nakama nakama[33257]: {"level":"error","ts":"2023-01-04T20:51:47.530+0100","caller":"server/runtime_lua.go:1178","msg":"Runtime RPC function caused an error","id":"sendmessage","error":"/var/lib/nakama-data/modules/sendmsg.lua:8: not a valid JSON string: invalid character '\\x00' looking for beginning of value\nstack traceback:\n\t[G]: in function 'json_decode'\n\t/var/lib/nakama-data/modules/sendmsg.lua:8: in main chunk\n\t[G]: ?"}
Jan  4 20:51:47 nakama nakama[33257]: {"level":"info","ts":"2023-01-04T20:51:47.535+0100","caller":"server/runtime_lua_nakama.go:1733","msg":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000m�Kt\u0000\u0000�\u0001��8s\u0000\u0000\u0000P8��s\u0000\u0000�\u0001\u0000\u0000\u0000t\u0000\u0000��a�Fs\u0000\u0000\u0000P�}8s\u0000\u0000\u0000\u0000p�Fs\u0000\u0000\u0000�ꬻt\u0000\u0000��V�+t","runtime":"lua"}
Jan  4 20:51:47 nakama nakama[33257]: {"level":"error","ts":"2023-01-04T20:51:47.535+0100","caller":"server/runtime_lua.go:1178","msg":"Runtime RPC function caused an error","id":"sendmessage","error":"/var/lib/nakama-data/modules/sendmsg.lua:8: not a valid JSON string: invalid character '\\x00' looking for beginning of value\nstack traceback:\n\t[G]: in function 'json_decode'\n\t/var/lib/nakama-data/modules/sendmsg.lua:8: in main chunk\n\t[G]: ?"}

On Android, when I request a leaderboard list with max 100 entries, I always get only 1 entry in return. Exact same code results on iOS and Mac correctly in a list with 100 entries.

Retrieving the Friendlist on Android works fine and the app correctly receives the list of friends (also if more than 1).

I am at a loss… what could be the problem? Same code. Same clients. But it just does not work on Android anymore. Is there a dependency I could have missed? Is there a build/link option that I have missed?

I did not change the code between the cocos and axmol versions and I did not change the shared client library (currently 2.5.1). All worked fine on Android before. NDK version did change from 19.2 to latest 25.1 (tried 23.2 too, same issue).

Solved it by using the 2.6.0 client for Android.

The documentation on of the clients is not up-to-date (or I looked in the wrong place) and in order to use 2.6.0 the following is needed:

  • The init call to set the JavaVM needs to be removed.

  • Now you need to pass the JavaVM and Application Context when creating the Client:

    parameters.platformParams.javaVM = JniHelper::getJavaVM();
    parameters.platformParams.applicationContext = JniHelper::getActivity();
  • You need to add a new dependency to the Java app gradle file:

implementation 'com.squareup.okhttp3:okhttp:4.9.1'