So, somewhat hard to ask. I wanna use the google play game service to access a leaderboard for my game. I tried to use BaseGameActivity like it is shown here Accessing the Games APIs
Tried a few things, did some search but cannot figure out the problem. My App crashes when the BaseGameActivity is started. Log error shows:
03-10 17:44:54.071: E/AndroidRuntime(31435): FATAL EXCEPTION: main
03-10 17:44:54.071: E/AndroidRuntime(31435): java.lang.IllegalStateException: A
fatal developer error has occurred. Check the logs for further information.
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$h.b(Unknown Source)
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$h.b(Unknown Source)
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$b.bR(Unknown Source)
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$a.handleMessage(Unknown Source)
Console shows:
[2014-03-10 17:47:18 - BaseGameUtils] Could not find BaseGameUtils.apk!
Answer: I had to do two metadata entrys about the appid in the manifest. The Log without filters listed the corresponding errors
The two entries were
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data
android:name="com.google.android.gms.appstate.APP_ID"
android:value="@string/app_id" />
only one of these entries were mentioned in the tutorial.
Reading with logcat Once you are able have the steps to reproduce the crash, you can use a tool like logcat to get more information. The logcat output will show you what other log messages you have printed, along with others from the system.
I've just finished putting up leaderboards and it was a pain, but I did it and it works. Here's a long list of suggestions that may directly or indirectly help you. I use Eclipse.
For Google Play API, minimum SDK is 9 so put this in your manifest on it's own line:
< uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/> //whatever target you want
Import the BaseGameUtils project to your workspace. You do not have to modify any of this code.
Import google-play-services_lib. This is in your sdk folder. My sdk folder is next to my eclipse folder. Anyways this is in: sdk/extras/google/google_play_services/libproject/google-play-services_lib. You do not have to modify any of this code.
Right Click on YourProject in the package explorer tab (normally on the left side of eclipse with all of your project folders). Then click on Properties (Alt+Enter). Then click on Android. On the bottom part of the Android page, should be "Library." Click the add button and add BaseGameUtils and google-play-services_lib. Do not click "Is Library".
Ensure all of the android-support-v4.jar files in all the relevant projects are using the same up-to-date version. You can update your support file by right clicking your project in the "package explorer" tab and going to ->Android Tools->Add Support Library. Then you accept and update. You can further check to see if all of the projects listed have this updated jar by right clicking your project and going to properties. Then click on Java Build Path and then Click on the libraries tab. You should see the support jar listed. If not, you can add the jar, where-ever it is located in the project. If you do not do this, you may have something called JAR MIXMATCH. Of course, you will see the exact problem in your console so this is easy to fix and diagnose.
Your manifest should be: < meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" /> < meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
The last line with @integer looks into the google_play_services_version so you don't have to do anything in the future whenever the google play version changes. Do not hard code the version number value or you will have to manually update it often.
MyProject extends BaseGameActivity.
Then to call the leaderboard and update it, their sample code of 2 lines of code runs great. See below. https://developers.google.com/games/services/android/leaderboards You have to pass in your leaderboard ID given to you when you link up your app to the google play developer console. It's a String that looks something like: "DkbGvageyBASEWEFCx." Updating and Getting a leaderboard will crash if you aren't connected. Check out this complete sample code below.
//to update if (getApiClient().isConnected()) //getAPIClient is part of BaseGameUtils Games.Leaderboards.submitScore(getApiClient(), leaderboardID, score);
//to show if (getApiClient().isConnected()) startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), leaderboardID), 1337);
Lastly, if you are using an app with a different keystore that has a different SHA1 (Secure Hash Algorithm) than the one that you have on the google play store, then there will be an error and you will not be able to connect. So if you uploaded an app with a keystore with an SHA1 like ab:cd:de... and you're debugging your app, you may see problems since Eclipse will use a default android debug keystore which has a different SHA1. You will not be able to connect and consequently, you will not be able to use any google play services.
I recommend you look at the sample code called "Trivial Quest." https://github.com/playgameservices/android-samples It's under eclipse_compat. This sample code shows one how to sign in and unlock an achievement. If you can sign in, you can do achievements and leaderboards really easily.
There's a lot of stuff but you have given us only a small piece of the puzzle. If you have any more problems, please let us know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With