I am trying to implement Google play Game Services into libGDX project. In my android project, the MainActivity looks like this:
public class MainActivity extends AndroidApplication implements
GameHelper.GameHelperListener, ActionResolver {
GameHelper gameHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameHelper = new GameHelper(this, GameHelper.CLIENT_ALL);
gameHelper.enableDebugLog(true);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
initialize(new CJSGame(this), cfg);
gameHelper.setup(this);
}
@Override
public void onStart() {
super.onStart();
gameHelper.onStart(this);
}
@Override
public void onStop() {
super.onStop();
gameHelper.onStop();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
gameHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean getSignedInGPGS() {
// TODO Auto-generated method stub
return gameHelper.isSignedIn();
}
@Override
public void loginGPGS() {
// TODO Auto-generated method stub
try {
runOnUiThread(new Runnable() {
public void run() {
gameHelper.beginUserInitiatedSignIn();
}
});
} catch (final Exception ex) {
}
}
@Override
public void submitScoreGPGS(int score) {
// TODO Auto-generated method stub
Games.Leaderboards.submitScore(gameHelper.getApiClient(),
getString(R.string.leaderboard1_id), score);
}
@Override
public void unlockAchievementGPGS(String achievementId) {
// TODO Auto-generated method stub
Games.Achievements.unlock(gameHelper.getApiClient(), achievementId);
}
@Override
public void getLeaderboardGPGS() {
// TODO Auto-generated method stub
startActivityForResult(
Games.Leaderboards.getLeaderboardIntent(
gameHelper.getApiClient(),
getString(R.string.leaderboard1_id)), 100);
}
@Override
public void getAchievementsGPGS() {
// TODO Auto-generated method stub
startActivityForResult(
Games.Achievements.getAchievementsIntent(gameHelper
.getApiClient()), 101);
}
@Override
public void onSignInFailed() {
// TODO Auto-generated method stub
System.out.println("Sign in failed");
}
@Override
public void onSignInSucceeded() {
// TODO Auto-generated method stub
System.out.println("Sign in succeeded");
}
}
When I try to run the application on android device, I end up with IllegalStateException error in the logcat:
03-13 10:23:40.766: E/AndroidRuntime(31339): FATAL EXCEPTION: main
03-13 10:23:40.766: E/AndroidRuntime(31339): java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
03-13 10:23:40.766: E/AndroidRuntime(31339): at com.google.android.gms.internal.dw$h.b(Unknown Source)
03-13 10:23:40.766: E/AndroidRuntime(31339): at com.google.android.gms.internal.dw$h.b(Unknown Source)
03-13 10:23:40.766: E/AndroidRuntime(31339): at com.google.android.gms.internal.dw$b.bR(Unknown Source)
03-13 10:23:40.766: E/AndroidRuntime(31339): at com.google.android.gms.internal.dw$a.handleMessage(Unknown Source)
03-13 10:23:40.766: E/AndroidRuntime(31339): at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 10:23:40.766: E/AndroidRuntime(31339): at android.os.Looper.loop(Looper.java:137)
03-13 10:23:40.766: E/AndroidRuntime(31339): at android.app.ActivityThread.main(ActivityThread.java:5419)
03-13 10:23:40.766: E/AndroidRuntime(31339): at java.lang.reflect.Method.invokeNative(Native Method)
03-13 10:23:40.766: E/AndroidRuntime(31339): at java.lang.reflect.Method.invoke(Method.java:525)
03-13 10:23:40.766: E/AndroidRuntime(31339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
03-13 10:23:40.766: E/AndroidRuntime(31339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
03-13 10:23:40.766: E/AndroidRuntime(31339): at dalvik.system.NativeStart.main(Native Method)
Any Help please??
Edit: I already have the meta-data tag in the manifest file
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
Solved, I enabled adb logcat and found that there is another metadata tag missing in the manifest file:
<meta-data android:name="com.google.android.gms.appstate.APP_ID"
android:value="@string/app_id" />
Just added this tag and it is working properly.
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