Google Play Services in LibGDX – Android

Past 2 weeks, I spent a lot of time trying to make Google Play Services library work in my LibGDX project. Even though the process is simple there are a few pit falls from which it might take some days to recover, like what happened to me. So I will outline the steps here to implement Google Play Services with minimum number of errors. (I’m not saying there won’t be any errors because LibGDX and Google updates stuff a lot)

Note: I’m writing this for Windows users. I haven’t tested this completely in Ubuntu yet. I will update this post later including that.

First off

Open Android SDK Manager and update the following to the latest version:

  • Android SDK Tools
  • Android SDK Platform-Tools
  • Android Support Repository
  • Google Play Services
  • Google Repository

Now install the SDK Platform and Android SDK Build-Tools for the API that you are targeting. That is, if you are developing for API 25 (Android 7.1.1), install the SDK Platform 25 and Android SDK Build-Tools version 25.0.2 (highest for 25 as of writing this).

 

JRE compatibility

If you’re working with a 64-bit OS, the IntelliJ IDEA shortcut that was created will still be pointing to the 32-bit program of the IDE. This may cause JRE conflict errors in some cases so it’s better to change the Start Menu/Desktop shortcut to open the 64-bit IDE. It can most likely be found in: C:\Program Files (x86)\JetBrains\IntelliJ IDEA Installation Dir\bin and the file is idea64.exe.

 

Adding the library

Import or open your LibGDX project as usual. Download the Android samples project from here and copy the BaseGameUtils folder found in android-basic-samples/BasicSamples/libraries and paste it to the root of your LibGDX project. Your root directory may look like this now:

Screenshot from 2017-01-04 22:24:09.png

project root structure

Open settings.gradle and add ‘BaseGameUtils’ to the end.

include 'desktop', 'android', 'ios', 'html', 'core', 'BaseGameUtils'

Open the root build.gradle and in the android project, add BaseGameUtils as a dependency:

...

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile project(":BaseGameUtils")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"

...

 

Finally, open the build.gradle in BaseGameUtils.

Change the appcombat, supportlibrary and gmslibrary version numbers to the latest that you downloaded just now. The latest version can be checked in android_sdk/extras/android/m2repository/com/android/support/appcompat-v7/, android_sdk/extras/android/m2repository/com/android/support/support-v4/ and android_sdk/extras/google/m2repository/com/google/android/gms/ folders respectively.

Change the app compile version, minimum version and build tools version to the same you specified in android build.gradle.

Screenshot from 2017-01-04 22:33:12.png

build.gradle of BaseGameUtils

That’s it! Now Sync the gradle and all libraries that are required to implement Google Play Services will be downloaded to the project.

To come: Using interfaces to call Google Play Services methods

Love Peace.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s