Before you begin
- You should have your Android development environment set up.
- You should have a physical device running Android 2.3 or higher for testing.
Step 1: Download SDK and prepare your device
To install the Google Play services SDK for development:
- Launch the SDK Manager.
- On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
- On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute android sdk.
- Install the Google Play services SDK.
- Scroll to the bottom of the package list, expand Extras, select Google Play services, and install it.
- The Google Play services SDK is saved in your Android SDK environment at <android-sdk>/extras/google/google_play_services/.
- Install a compatible version of the Google APIs platform.
- If you want to test your app on the emulator, expand the directory for Android 4.2.2 (API 17) or a higher version, select Google APIs, and install it. Then create a new AVD with Google APIs as the platform target.
- Note: Only Android 4.2.2 and higher versions of the Google APIs platform include the Google Play services.
Step 2: Setup the game in the Developer Console
The Google Play Developer Console is where you manage game services for your game and configure metadata for authorizing and authenticating your game.
To set up the sample game in the Developer Console:
- Point your web browser to the Developer Console and sign in. If you haven't registered for the Developer Console before, you will be prompted to do so.
- Follow these instructions to add your game to the Developer Console.
- When you are asked about using Google APIs in your app, select I don’t use any Google APIs in my game yet.
- For the purpose of this training you can fill up the form with your own game details. For convenience you can use the placeholder icons and screenshots provided in the Downloads page.
- Follow these instructions to generate an OAuth 2.0 client ID for your Android app.
- When linking your Android app, make sure to specify the exact package name you used previously while renaming sample package.
- You can use the Unity to generate a new Keystore and signed certificate if you don’t have one already. To learn how to generate a new Keystore and signed certificate, see Compile and sign with Unity.
- Make sure to record the following information for later:
- Your application ID: This is a string consisting only of digits (typically 12 or more) at the beginning of your client ID.
- Your signing certificate: Note which certificate you used when you set up your API access (the certificate whose SHA1 fingerprint you provided). You should use the same certificate to sign your app during testing or releasing your app.
- Configure achievements for your game:
- Select the Achievements tab in the Developer Console.
- Add the achievements:
- Record the IDs (long alphanumeric strings) for each achievement that you created.
- Configure achievements that are appropriate for your game. To learn more, see the concepts behind achievements.
- Configure the leaderboards:
- Select the Leaderboards tab in the Developer Console.
- Add the leaderboards.
- Record the IDs (long alphanumeric strings) for each leaderboard you created.
- Configure leaderboards that are appropriate for your game. To learn more, see the concepts behind leaderboards.
- Add test accounts for your game. This step is needed only for apps that have not been published in the Developer Console yet. Before the app is published, only the test accounts listed in the Developer Console can log in. However, once an application is published, everyone is allowed to log in.
Step 3: Prepare Resources
To run the game, you need to configure the application ID as a resource in your Android project. You will also need to add games metadata in the AndroidManifest.xml. Open Assets/Plugins/Android/AN_Res/res/values/ids.xml
and replace the placeholder IDs.
- Specify your application ID in the app_id resource.
- Specify each achievement ID that you created earlier in the corresponding achievement_* resource.
- Specify each leaderboard ID that you created earlier in the corresponding leaderboard_* resource.
Step 4: Test your game
To ensure that game services are functioning correctly in your game, test the application before you publish it on the Google Play. You can get started from plugin play service example scenes, but do not forget to update example variables with your project values.
Note: It's recommended to test on a physical Android device. However, if you do not have a physical device, you can test on the Android Emulator. To do so, download the emulator system image that includes the Google Play Services, under Android 4.2.2, from the SDK Manager.
To run your game on your physical test device:
- Verify that you have set up the test account that you are using to login to the app (as described in Step 2).
- Export an APK and sign it with the same certificate that you used to set up the project in Developer Console.
- Install the signed APK on your physical test device.
After all preparation is ready, you can start playing. The API usage guidelines will be described in the next articles of this chapter. Or you can start with Playmaker actions.