libGDX Google Play 游戏服务 - Android

libGDX Google Play Game Services - Android(libGDX Google Play 游戏服务 - Android)

本文介绍了libGDX Google Play 游戏服务 - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Google play 游戏服务实施到 libGDX 项目中.在我的 android 项目中,MainActivity 如下所示:

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");
}
}

当我尝试在 android 设备上运行应用程序时,我最终在 logcat 中出现 IllegalStateException 错误:

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)

有什么帮助吗??

我已经在清单文件中有元数据标签

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" />

推荐答案

已解决,我开启了adb logcat,发现manifest文件中又少了一个元数据标签:

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.

这篇关于libGDX Google Play 游戏服务 - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:libGDX Google Play 游戏服务 - Android