我的程序运行正常
package com.mygdx.game.android;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.example.games.basegameutils.GameHelper;
import com.google.example.games.basegameutils.GameHelper.GameHelperListener;
import com.mygdx.game.I_interface;
import com.mygdx.game.MyGdxGame;
public class AndroidLauncher extends AndroidApplication implements GameHelperListener{
private Context context;
private GameHelper gameHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("onCreate", "Inside onCreate");
context = AndroidLauncher.this;
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
myInterface = new AndroidLauncher();
config.useWakelock = true;
config.useAccelerometer = true;
config.useCompass = false;
RelativeLayout layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView = initializeForView(new MyGdxGame(myInterface), config);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layout.addView(gameView);
setContentView(layout);
if(gameHelper == null) {
gameHelper = new GameHelper(this,GameHelper.CLIENT_ALL);
gameHelper.enableDebugLog(true);
}
gameHelper.setup(this);
//signin();
}
public void signin(){
//Run this code on the main thread.
runOnUiThread(new Runnable() {
@Override
public void run() {
//Check if user is signed in
try{
//if not, attempt to sign in
gameHelper.beginUserInitiatedSignIn();
}
catch (Exception e) {
//Handle errors with an alert box
AlertDialog.Builder alert = new AlertDialog.Builder(AndroidLauncher.this);
alert.setTitle("Unable to sign in");
alert.setMessage("The app was unable to sign in to G+. An error occured.");
alert.setPositiveButton("Ok", null);
alert.show();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
gameHelper.onActivityResult(requestCode, resultCode, intent);
}
@Override
public void onSignInFailed() {
}
@Override
public void onSignInSucceeded() {
}
}
但是,一旦我打电话给signin开始google playservices它就会显示致命异常
07-22 07:16:39.882: E/AndroidRuntime(4468): FATAL EXCEPTION: main
07-22 07:16:39.882: E/AndroidRuntime(4468): java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
07-22 07:16:39.882: E/AndroidRuntime(4468): at com.google.android.gms.internal.ff$h.b(Unknown Source)
07-22 07:16:39.882: E/AndroidRuntime(4468): at com.google.android.gms.internal.ff$h.a(Unknown Source)
07-22 07:16:39.882: E/AndroidRuntime(4468): at com.google.android.gms.internal.ff$b.eN(Unknown Source)
07-22 07:16:39.882: E/AndroidRuntime(4468): at com.google.android.gms.internal.ff$a.handleMessage(Unknown Source)
07-22 07:16:39.882: E/AndroidRuntime(4468): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 07:16:39.882: E/AndroidRuntime(4468): at android.os.Looper.loop(Looper.java:137)
07-22 07:16:39.882: E/AndroidRuntime(4468): at android.app.ActivityThread.main(ActivityThread.java:4517)
07-22 07:16:39.882: E/AndroidRuntime(4468): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 07:16:39.882: E/AndroidRuntime(4468): at java.lang.reflect.Method.invoke(Method.java:511)
07-22 07:16:39.882: E/AndroidRuntime(4468): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
07-22 07:16:39.882: E/AndroidRuntime(4468): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
07-22 07:16:39.882: E/AndroidRuntime(4468): at dalvik.system.NativeStart.main(Native Method)
我猜我的电话程序有问题。 由于没有示例项目可供libgDx使用最新版本的google play服务 我被困住了。
感谢您的回答。
答案 0 :(得分:2)
解决了, link
实际上我正在使用所有客户端
if(gameHelper == null) {
gameHelper = new GameHelper(this,GameHelper.CLIENT_ALL);
gameHelper.enableDebugLog(true);
}
这就是为什么我需要在我的清单中添加游戏状态和游戏的应用ID
<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" />
而Voila,已经完成了