Coder Social home page Coder Social logo

rayyee / cpp-crossplatform-minimal-sample Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 22.0 250 KB

A minimal sample demonstrating how to share C++ games code between iOS and Android projects

License: Apache License 2.0

Makefile 2.12% C++ 41.88% Shell 3.13% Java 20.39% C 3.52% Objective-C 15.69% Objective-C++ 13.15% Ruby 0.12%

cpp-crossplatform-minimal-sample's Introduction

ComboSample

Introduction

This sample demonstrates building an app with Google Play Games on iOS and Android with a single C++ code base.

Project Structure

  • 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.
    • 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.
  • 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.
  • 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 the GLSurfaceView in Android.
    • logging.h - defines cross-platform LOGI(...) macro to use NSLog(...) on iOS and Log.i(...) on Android.

Set-up

Requirements

Google Play Games

  1. Create an entry for your game in the Google Play Developer Console by following these instructions.
  2. 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 Identifier com.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.
  3. Download the Play Games C++ SDK and extract it to a directory on your development machine.

Android

  1. In your local development environment, set the following variables:
    1. SDK_ROOT - the location of your Android SDK folder. Add SDK_ROOT/tools and SDK_ROOT/platform-tools to your PATH.
    2. NDK_ROOT - the location of your Android NDK folder. Add NDK_ROOT to your PATH.
    3. 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.
  2. Import the project into Eclipse:
    1. Click File > Import > Android > Existing Android Code into Workspace.
    2. Select the android directory of this sample and click OK.
  3. Import the Appcompat v7 library:
    1. Click File > Import > Android > Existing Android Code into Workspace.
    2. Select the SDK_ROOT/extras/android/support/v7/appcompat folder and click OK.
    3. Right click the ComboSample project and select Properties > Android and add a Library reference to the android-support-v7-appcompat project that you just imported. Remove any pre-existing broken Library references.
  4. Import the Google Play Services library:
    1. Click File > Import > Android > Existing Android Code into Workspace.
    2. Select the SDK_ROOT/extras/google/google_play_services/libproject folder and click OK.
    3. Right click the ComboSample project and select Properties > Android and add a Library reference to the google_play_services-lib project that you just imported.
  5. In android/res/values/ids.xml replace the app_id value with your App ID from the Google Play Developers Console.

iOS

  1. Navigate to the ios/ComboSample directory and run pod install. This uses cocoapods to install the latest version of the Play Games SDK for iOS.
  2. Open the file ComboSample.xckworkspace which was generated by the previous command. This should open XCode with the ComboSample project.
  3. Under Build Settings > Framework Search Paths add an entry to SDK_PATH/ios where SDK_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 to NDK_MODULE_PATH/gpg-cpp-sdk/ios.
  4. In ViewController.mm change the value of kClientID to the iOS client ID you obtained earlier.

Build and Run

  1. To build the C++ code for use with the Android NDK, navigate to the android/jni directory and run ndk-build.

  2. Run the Android app on a physical Android device with Android 2.3.3 or later and Google Play Services installed.

  3. Run the iOS app on a physical iOS device or simulator with iOS 7.0 or later.

  4. 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:

    Android and iOS

cpp-crossplatform-minimal-sample's People

Contributors

naokigoogle avatar samtstern avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.