This sample demonstrates building an app with Google Play Games on iOS and Android with a single C++ code base.
- android/ - All Android-specific code, including JNI code.
- src/ - Java source code.
- MainActivity.java - Main
Activity
for the application. Uses the JNI to call the C++ SDK for sign-in, leaderboards, etc.
- MainActivity.java - Main
- jni/ - JNI source code, including C++ headers for native methods in the Java source.
- AndroidMain.cpp - Android-specific lifecycle methods for initializing Google Play Games.
- MainActivity.cpp - implementation of native methods in
MainActivity.java
. - GLRenderer.cpp - implementation of native methods in
GLRenderer.java
.
- make_headers.sh - script to generate headers for native methods in Java classes.
- src/ - Java source code.
- ios/ - All iOS-specific code.
- ComboSample/ComboSample/ - main iOS app project.
- ViewController.mm - Main
ViewController
for the application. Uses Objective-C++ to call the C++ SDK for sign-in, leaderboards, etc.
- ViewController.mm - Main
- ComboSample/ComboSample/ - main iOS app project.
- cpp/ - All shared C++ code.
- StateManager.cpp - code for interacting with Google Play Games.
- GLDrawer.cpp - OpenGL code to render the
GLKView
in iOS and theGLSurfaceView
in Android. - logging.h - defines cross-platform
LOGI(...)
macro to useNSLog(...)
on iOS andLog.i(...)
on Android.
- Android NDK Revision 9d or higher
- Android SDK v10 or higher and latest Eclipse ADT
- The latest version of the Google Play Services SDK
- The Play Games C++ SDK
- Cocoapods
- Create an entry for your game in the Google Play Developer Console by following these instructions.
- Link an Android app and an iOS app to your project. For Android use the package name
com.google.example.combosample
. For iOS use the Bundle Identifiercom.google.example.ComboSample
. Make sure to keep track of your App ID and the Client ID for your iOS app, you will need these later. - Download the Play Games C++ SDK and extract it to a directory on your development machine.
- In your local development environment, set the following variables:
SDK_ROOT
- the location of your Android SDK folder. AddSDK_ROOT/tools
andSDK_ROOT/platform-tools
to yourPATH
.NDK_ROOT
- the location of your Android NDK folder. AddNDK_ROOT
to yourPATH
.NDK_MODULE_PATH
- the location of the folder containing the Play Games C++ SDK folder. This is not the location of the C++ SDK but rather the directory above it.
- Import the project into Eclipse:
- Click File > Import > Android > Existing Android Code into Workspace.
- Select the
android
directory of this sample and click OK.
- Import the Appcompat v7 library:
- Click File > Import > Android > Existing Android Code into Workspace.
- Select the
SDK_ROOT/extras/android/support/v7/appcompat
folder and click OK. - Right click the
ComboSample
project and select Properties > Android and add a Library reference to theandroid-support-v7-appcompat
project that you just imported. Remove any pre-existing broken Library references.
- Import the Google Play Services library:
- Click File > Import > Android > Existing Android Code into Workspace.
- Select the
SDK_ROOT/extras/google/google_play_services/libproject
folder and click OK. - Right click the
ComboSample
project and select Properties > Android and add a Library reference to thegoogle_play_services-lib
project that you just imported.
- In
android/res/values/ids.xml
replace theapp_id
value with your App ID from the Google Play Developers Console.
- Navigate to the
ios/ComboSample
directory and runpod install
. This uses cocoapods to install the latest version of the Play Games SDK for iOS. - Open the file
ComboSample.xckworkspace
which was generated by the previous command. This should open XCode with the ComboSample project. - Under Build Settings > Framework Search Paths add an entry to
SDK_PATH/ios
whereSDK_PATH
is the path to the Play Games C++ SDK folder (gpg-cpp-sdk
) on your machine. If you followed the instructions for Android this should be equivalent toNDK_MODULE_PATH/gpg-cpp-sdk/ios
. - In
ViewController.mm
change the value ofkClientID
to the iOS client ID you obtained earlier.
-
To build the C++ code for use with the Android NDK, navigate to the
android/jni
directory and runndk-build
. -
Run the Android app on a physical Android device with Android 2.3.3 or later and Google Play Services installed.
-
Run the iOS app on a physical iOS device or simulator with iOS 7.0 or later.
-
When running the app, you should see four buttons (Sign In, Sign Out, Show Achievements, and Show Leaderboards) as well as a colored square. The four buttons trigger methods in the Play Games SDK and the square is a demonstration of using OpenGL graphics in a cross-platform application. See the screenshot below: