Google Play Online Subsystem not working

I’m trying to set up achievements in my android game. I have enabled the google play services through the project settings. I have also uncommented the section in the build.cs for the online subsystems. I know how to get the app into the google play store, and have everything set up on the google play store end. However, every time I try to connect to the google play services, I receive the errors:

“ConnectToService - Invalid or uninitialized OnlineSubsystem”

“ConnectToService - Cannot map local player to unique net ID”

As far as I can tell, by browsing through the source code, the first error occurs when the IOnlineSubsystem* OnlineSub == nullptr when I try to connect. I’m out of things to try. What am I missing, or what am I doing wrong?

Did you manage to solve this problem? I’ve got a similar issue :frowning:

Hi Nefusadi,

There are a couple things you can look at, first of all, make sure “OnlineSubsystemGooglePlay” is one of the uncommented dependencies the Build.cs.

Also, check for DefaultPlatformService in your DefaultEngine.ini file. On Android, this should default to “GooglePlay”, but it might be getting overridden. You can try making sure this is in your DefaultEngine.ini:

1 Like

Based on those errors, it looks like it’s trying to compile the Google Play subsystem for Windows, which is not supported. Try moving the PrivateDependencyModuleNames.Add(“OnlineSubsystemGooglePlay”) into an if (Target.Platform == UnrealTargetPlatform.Android) block.

I had already added the DefaultPlatformService=GooglePlay to the ini file, but I went ahead and added: PrivateDependencyModuleNames.Add(“OnlineSubsystemGooglePlay”); right after the dependency for “OnlineSubsystem” to interesting effect. It now gives compile errors for UE4Editor-OnlineSubsystemGooglePlay.dll stating:

Cannot open include file: ‘jni.h’: no such file or directory

Cannot open include file: ‘gpg/achievement_manager.h’: no such file or directory

I tried re-downloading the required dependencies, and then re-creating the project files, but the errors persist.

Ok, wrapping in the conditional allowed me to compile everything, but now the packaged game gives me a black screen for a second before immediately shutting down. I tried recompiling the .so and doing a full rebuild of my game as well.

Edit: I launched a development build of the game to see if I could get an error message from it, but it ended up running as expected (including asking to sign in, which failed due to the fact that it’s an unsigned build) but if I go back to a shipping release, it continues to close out immediately after starting up.

Edit2: I should have looked at it earlier, but LogCat is showing that when I try to launch the app I get a whole list of errors of the format:

Exception in java/lang/ClassLoader.loadClass: java.lang.ClassNotFoundException: Didn’t find class"[everything from achievements to leaderboards to multiplayer to snapshot, etc.]" on path: /data/app/com.epicgames.HarbingerOfTruth-1.apk.

Additionally, there’s a whole bunch of permission denied warnings for getCurrentUser() from android.permission.INTERACT_ACROSS_USERS, though it’s difficult to tell if they’re all related to my game.

Any idea why the classes aren’t ending up in the .apk on the shipping build? I’d really like to get the achievements working.

The missing classes are probably a result of running Proguard, which we do for shipping builds. Proguard will strip classes that it doesn’t think are required from the final APK. We have exceptions for the Google Play SDK in the engine’s proguard-project.txt, so all the required classes should be there. If you’re using a custom proguard-project.txt file for your game, make sure it has the same exceptions for Google Play that are in Engine\Build\Android\Java\proguard-project.txt.

As far as I know none of the engine code requires the INTERACT_ACROSS_USERS permission, so I suspect this is just log spam from other apps, but you can experiment with adding it to AndroidManifest.xml if you like.

1 Like

Yup! Turns out a proguard-project.txt file had been generated for my project, and was missing two sections in the google play services part. It’s all working now, thanks for your help!