Famous Last Words

[Warning: Technical, rambling post ahead.  But if you got here searching about Google Play Game Services in Unity, you’ve reached the right page.]

Last week, I briefly mentioned how I was “optimistic” about getting Google Play Game Services to work for Inferno 2.  I was wrong on so many levels.

It’s not like GameCenter (iOS) or GameCircle (Amazon) have always been a stroll in the park, but adding support for them is a mundane and straightforward task in a Unity project at this point.  Google Play Game Services is, on the other hand, the most terrible of all achievement systems that you can ever fear to work with as a developer.  I write this account of my experience with it both as a way to shame Google/Unity (mostly Google) into somehow improving the system, and as a potential aid to other developers who run into one of the many obstacles in implementing GPGS.

The Plug-In Selection

First, you need to decide which plug-in for GPGS you want to use.  I’ve bought one off the Unity Asset Store (can’t remember the name), the one directly from Prime31, and I’ve also downloaded Google’s kind-of official plug-in.  I chose to use the one from Prime31 for Inferno 2, because it was updated over the summer, so it seemed most likely to work, and there is decent documentation for it, and I’ve had good luck with their other plug-ins.  [With GameCenter, I use the Prime31 one even though Unity has it built-in now as well, just because I’ve always used it and it always works.  For Amazon, there’s only one plug-in, the official one.]

Things started out a little rough.  I managed to get the achievement list uploaded to Google Play, but  there was one hiccup when trying to connect the achievements to the actual project.  Inferno 2 didn’t show up in the list of games I could link the achievement list to.  After trying many settings on the project end, it turns out Inferno 2 is the 11th game I created in Google Play, and the list only shows 10.  I had to manually type “Inferno 2″, then it shows up as a selectable project to link.  After I figured that out, I downloaded the list of unintelligible achievement IDs [GameCenter and GameCircle both let you set the IDs to whatever you want] and hooked up all the calls to the plug-in in code.

There’s just a small amount of manual setup for the AndroidManifest for the Prime31 plug-in, and then I built the game and uploaded it to my Moto G to test.

And the game doesn’t even run.  The debug log says something about a not finding the correct activity.  A search turns up nothing of possible assistance, so I give up in frustration for the night.  At this point I’m ready to give up on GPGS already.

The “Official” Plug-In

The next night I remove the Prime31 plug-in, and decide to try the kind-of official (but not) one on GitHub.  When I get that downloaded and installed in the Unity project, the “Android Setup” button informs me I’m using a very outdated set of libraries for GPGS and need to update.

I fire up the Android SDK Manager, and it says Google Play Services are up to date (version 10).  I update everything that can be, which takes 30+ minutes, and try the Setup button in Unity again.  Still out of date.  Restart Unity.  Still out of date.

I uninstall Google Play Services in the SDK Manager.  And it doesn’t show up at all any more.  Restart the SDK Manager, and a whole mess of new options appear, including Google Play Services (version 16 or so).  Update everything again (30+ minutes of waiting), and the Setup button in Unity now works.

But Unity can no longer build after I update the calls to use the new plug-in.  The zipalign tool is failing.  Not sure why, but a search reveals that the zipalign tool should be in the Android SDK Tools folder.  I look, and it’s not there.  The solution is to update the Android SDK, but I’ve just done that.  Turns out it got moved (recently?) to the Build-Tools folder.  So I copy it back to the Tools folder, and Unity builds again.

On the device, the game runs, but trying to log in does nothing, so I close the game.  I don’t see the relevant input in the debugger, so I restart the game and try again.  Turns out I didn’t wait long enough, as it takes at least 20 seconds to login to GPGS the first time you do it.  There are then 4 different screens with various warnings about Inferno 2 trying to access my information, all with the button “Sign In” on them.  Keep pushing the button, and it pops up “Game is not correctly configured/authorized”, so I check the debug output like it says.  The most obvious thing is “APP ID: ???”.

I use the instructions from the Prime31 plug-in to make sure the APP ID is set in the AndroidManifest file.  Same error.  Notice that it lists the certificate SHA (a long hexidecimal number unique to each developer).  I check on the developer console.  No, not the main one.  Not the one that lists the achievements.  The other hidden one that lists your game’s API usage.  The SHA there does not match the one that the debug output lists.

That SHA (on the dev console) can’t be used by me without uploading the game to Google Play, so I try to add the SHA from the debug output.  Not a valid device SHA, it says.  Can’t figure out how to get the debug SHA from my keystore either (there are two ways to sign each keystore, debug or release, but I can only get the release SHA).

The Beta Plan

Now what?  I decide to try using Google Play’s Beta service to allow me to download the release version, which will match the SHA on the developer console (you can’t load that version on your device manually).  So I upload a build to the Beta APK uploader.

Then I have to use a Google Group to invite beta testers.  I create a Group, invite myself to it, and try to invite the group on the developer console.  Says it’s not a valid group.  I wait 5 minutes.  Still not a valid group.  Try the URL to the group.  Nope.  Search again (StackOverflow is invariably the place I find these answers), and I have to use the email address of the group.

Now I get an email inviting me to beta test Inferno 2.  Yay!  But the link doesn’t work yet, because it takes a few hours for a build to become available.  Time for bed.

Next morning, still not working.  After 3 more hours, I try creating a new Gmail account, get the invite sent to it.  Link doesn’t work for that account either.

16 hours after I uploaded it to Google, the link starts working.  I can see Inferno 2 on the Play Store (but nobody else can).  It says it’s $2.99, and a quick search reveals that *you have to buy a game to Beta test it*.  Seriously.  You can’t set it to Free, because once you do, it’s free forever.

So I try to buy it.  “An error occurred processing your order.”  Try with Paypal instead of my credit card.  Same problem.  Try for a couple more hours.

Debug Keystore to the Rescue

Give up in frustration (again).  Then decide to try using the debug.keystore to build the game.  I find the SHA from debug.keystore (keytool.exe is your friend), and upload it to the hidden developer console (accepted!).

I build the game with the debug keystore, and it looks like I completed the sign in process in the game.

Yay!

But, it doesn’t work the second time I try.  So I delete the game and reinstall.  First time works.  Second time, nothing.

I add more logic, and the game is never being told the sign-in completed.  Nothing obvious on the plug-in page about this (I check the default sample to make sure I didn’t miss anything).

Then I notice a new version of the plug-in was uploaded 2 days ago (2 days after I downloaded it the first itme).  It says “fixes an issue if you try Android Setup multiple times”.

I download it and there are 2 new files (neither of which looks relevant), then build the game and go off to put my daughters to bed.  At this point, I’m back to the point of wanting to fling my Moto G against the wall (the 3rd time I’ve felt that way in a week, all because of GPGS).

I come back and fire up the game, and it works completely.  It tells the game you’ve signed in, and it works every time.  After four frustrating nights of working on it, GPGS is finally working, and the final step was a complete mystery as to why it worked.

It’s Over?

And such is the way for GPGS.  There are many mysteries, and sources of frustration, and plain dumb things about it.  I obviously took many wrong detours along the way, and who knows if the Prime31 plug-in would have worked if I only had updated the Android SDKs (twice) before trying it, and used the debug keystore.  For version 1.1, I’m forcing you to press the Google Login button every time you fire up the game, because I don’t know how it’ll work if I try to automatically sign-in.  I’m not even 100% sure it’ll work once the game is released.

Will I add GPGS to games prior to Inferno 2?  I don’t know right now.  If Google asks me to and will feature the games if I do, then of course I would.  Otherwise, I have no idea.

The good news is that I think I’m done with GPGS for now.  Except for the leaderboards on New Game+.  I’m “optimistic” that will go smoother than everything else with GPGS.

Comments are closed.