libGDX Google Play 游戏服务 - Android
Posted
技术标签:
【中文标题】libGDX Google Play 游戏服务 - Android【英文标题】:libGDX Google Play Game Services - Android 【发布时间】:2014-04-17 18:57:57 【问题描述】:我正在尝试将 Google play 游戏服务实施到 libGDX 项目中。 在我的 android 项目中,MainActivity 如下所示:
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 错误:
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)
有什么帮助吗??
编辑:我已经在清单文件中有元数据标签
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
【问题讨论】:
【参考方案1】:已解决,我启用了adb logcat,发现manifest文件中又少了一个元数据标签:
<meta-data android:name="com.google.android.gms.appstate.APP_ID"
android:value="@string/app_id" />
刚刚添加了这个标签,它工作正常。
【讨论】:
以上是关于libGDX Google Play 游戏服务 - Android的主要内容,如果未能解决你的问题,请参考以下文章
libGDX Google Play 游戏服务 - Android
Google Play 游戏服务和 libGDX“SignInActivity 必须以 startActivityForResult 启动”
如何通过 LibGdx 使用 Google Play 游戏服务
libGDX - Android Studio 中的 Google Play 游戏服务