Thursday, April 9, 2015

Play Services

After a lot of work trying to figure out issues with Google and Android SDK libraries, I've got the Google Play Games API working! (by "a lot of work" I mean maybe 3 or 4 hours....I guess that's not so bad)

Based on the results of the votes, the answer sounds like I should go ahead and use the games services to their full potential. Here's a test run of unlocking the first achievement!



This tutorial was super helpful in figuring out how to get started. Although there were a few hiccups that I'll document here in case the answer is helpful to anyone (or myself next time!)

First, I got all sorts of errors with not being able to find the right libraries. As many forums have mentioned, the dependencies specified in the build.gradle file have to match the SDK version that you download using the Android SDK manager. The working combination that folks are recommending as of today (Apr 2015) is the following in build.gradle:

        compile 'com.android.support:appcompat-v7:21.0.3'
        compile 'com.google.android.gms:play-services:7.0.0'

With that, you need to download the v21 (Android 5.0.1) SDK in the Android SDK Manager. Also, you have to scroll ALL THE WAY TO THE BOTTOM of the SDK Manager, and find "Google Play Services" in the "Extras" folder:


Once that is done, I'd either need to recreate the IDEA project file (using the "idea" task in gradle), or manually add the jars for those files to the classpath in IDEA. (I'd recommend recreating the IDEA project file -- I tried adding them manually, which worked for development, but not for deploying to my phone, so I ended up having to build/deploy from the command line).

Also, the example code from the tutorial linked above is out of date for making calls to the games service. As this forum post discusses, instead of trying to use gamesHelper.getGamesClient(), you need to make static calls using the Games class:

   Games.Achievements.unlock(gameHelper.getApiClient(), "(your achievement id)");

Once I did that, I was almost there! The only other thing I had to do was go back and sign my apk with the same production key that I used to create and push the app on the play store. Once that was done, everything just worked!

No comments:

Metatile Designer

For the NES game, I'm building my levels out of 32x32 pixel metatiles.  What is a metatile?  The NES background tiles are 8x8 pixels, bu...