GameHelper崩溃的应用程序启动 [英] GameHelper crashing at application start

查看:549
本文介绍了GameHelper崩溃的应用程序启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想它会帮地说,我用LibGDX。

code:

 包com.fmeg.tapout.android;进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;进口com.applifier.impact.android.ApplifierImpact;
进口com.badlogic.gdx.backends.android.AndroidApplication;
进口com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
进口com.fmeg.tapout.ActionResolver;
进口com.fmeg.tapout.TapoutGame;
进口com.google.android.gms.games.Games;
进口com.google.example.games.basegameutils.GameHelper;
进口com.google.example.games.basegameutils.GameHelper.GameHelperListener;公共类AndroidLauncher扩展AndroidApplication
    实现GameHelperListener,ActionResolver {    私有静态最后弦乐EVERPLAY_GAME_ID =14234;    私人GameHelper gameHelper;    公共AndroidLauncher(){    }    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration配置=新AndroidApplicationConfiguration();        ApplifierImpact.setDebugMode(假);
        ApplifierImpact.setTestMode(假);
        ApplifierImpact冲击=新ApplifierImpact((活动)这一点,EVERPLAY_GAME_ID);
        ApplifierImpact.instance.changeActivity(本);        gameHelper =新GameHelper(这一点,GameHelper.CLIENT_ALL);
        gameHelper.setup(本);        初始化(新TapoutGame(冲击,这一点),配置);    }    @覆盖
    公共无效调用onStart(){
        super.onStart();
// gameHelper.onStart(本);
    }    @覆盖
    公共无效的onStop(){
        super.onStop();
// gameHelper.onStop();
    }
    @覆盖
    公共无效的onActivityResult(INT要求,INT响应,意图数据){
        super.onActivityResult(请求,响应数据);
// gameHelper.onActivityResult(请求,响应数据);
    }    @覆盖
    公共无效onSignInFailed(){
        // TODO自动生成方法存根    }    @覆盖
    公共无效onSignInSucceeded(){
        // TODO自动生成方法存根    }    @覆盖
    公共无效unlockAchievement(字符串achievementID){
        Games.Achievements.unlock(gameHelper.getApiClient(),achievementID);
    }    @覆盖
    公共无效achivementProgress(字符串achievementID,INT进展){
        Games.Achievements.increment(gameHelper.getApiClient(),achievementID,进展);
    }    @覆盖
    公共无效submitScoreToLeaderboard(字符串leaderboardID,诠释得分){
        Games.Leaderboards.submitScore(gameHelper.getApiClient(),leaderboardID,分);
    }    @覆盖
    公共无效displayLeaderboard(字符串leaderboardID){
        startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(),leaderboardID),101);
    }    @覆盖
    公共无效shareScore(字符串的挑战,诠释得分){
        意图sendIntent =新的Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT,我设法+分+ +挑战的过程中水龙头+,而玩挖掘出的速度有多快你是挑战世界#FMEGTapout立即下载HTTP:!?!//位。 LY / FMEGTapout);
        sendIntent.setType(text / plain的);
        startActivity(sendIntent);
    }}

以上code编译并运行正常,但是只要你尝试使用谷歌播放服务,如更新分数或成就,你得到这个错误之一:

 一月五日至24日:19:11.413:E / AndroidRuntime(24280):致命异常:定时器0
一月五日至24日:19:11.413:E / AndroidRuntime(24280):java.lang.IllegalStateException:GoogleApiClient尚未连接。
一月五日至24日:19:11.413:E / AndroidRuntime(24280):在com.google.android.gms.internal.fq.a(来源不明)
一月五日至24日:19:11.413:E / AndroidRuntime(24280):在com.google.android.gms.common.api.b.b(来源不明)
一月五日至24日:19:11.413:E / AndroidRuntime(24280):在com.google.android.gms.games.internal.api.AchievementsImpl.unlock(来源不明)
一月五日至24日:19:11.413:E / AndroidRuntime(24280):在com.fmeg.tapout.android.AndroidLauncher.u​​nlockAchievement(AndroidLauncher.java:77)
一月五日至24日:19:11.413:E / AndroidRuntime(24280):在com.fmeg.tapout.screens.GameOver.handleAchievements(GameOver.java:98)
。1月5日至24日:19:11.413:E / AndroidRuntime(24280):在com.fmeg.tapout.screens.GameOver<&初始化GT;(GameOver.java:36)
一月五日至24日:19:11.413:E / AndroidRuntime(24280):在com.fmeg.tapout.screens.Tick.run(Play.java:85)
一月五日至24日:19:11.413:E / AndroidRuntime(24280):在java.util.Timer中的$ TimerImpl.run(Timer.java:284)

此外,在AndroidLauncher.java如果取消以下行

  @覆盖
公共无效调用onStart(){
    super.onStart();

// gameHelper.onStart(本);
    }

  @覆盖
公共无效的onStop(){
    super.onStop();

// gameHelper.onStop();
    }

  @覆盖
公共无效的onActivityResult(INT要求,INT响应,意图数据){
    super.onActivityResult(请求,响应数据);

// gameHelper.onActivityResult(请求,响应数据);
    }

该应用程序会崩溃在启动,这是它如何应该是根据我一直在使用的参考反正调用。崩溃的错误表明:

 一月五日至24日:32:19.854:E / AndroidRuntime(25552):致命异常:主要
一月五日至24日:32:19.854:E / AndroidRuntime(25552):java.lang.IllegalStateException:发生致命错误开发商。检查的详细信息的日志。
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在com.google.android.gms.internal.ff $ H.B(来源不明)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在com.google.android.gms.internal.ff $ h.a(来源不明)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在com.google.android.gms.internal.ff $ b.eN(来源不明)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在com.google.android.gms.internal.ff $ a.handleMessage(来源不明)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在android.os.Handler.dispatchMessage(Handler.java:99)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在android.os.Looper.loop(Looper.java:137)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在android.app.ActivityThread.main(ActivityThread.java:5455)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在java.lang.reflect.Method.invokeNative(本机方法)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在java.lang.reflect.Method.invoke(Method.java:525)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1187)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
一月五日至24日:32:19.854:E / AndroidRuntime(25552):在dalvik.system.NativeStart.main(本机方法)


<一href=\"https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/tutorial-libgdx-gameservices-android/src/com/theinvader360/tutorial/libgdx/gameservices/MainActivity.java\" rel=\"nofollow\">https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/tutorial-libgdx-gameservices-android/src/com/theinvader360/tutorial/libgdx/gameservices/MainActivity.java

https://developers.google.com/games/services/android/leaderboards < /一>


解决方案

您code看起来不错。然而,由于您使用的是 CLIENT_ALL (即所有Google Play游戏服务),您将需要添加的两个以下到您的清单中:

 &LT;元数据机器人:名字=com.google.android.gms.games.APP_ID机器人:值=@字符串/ APP_ID/&GT;
&LT;元数据机器人:名字=com.google.android.gms.appstate.APP_ID机器人:值=@字符串/ APP_ID/&GT;

首先需要登录,第二个是需要云节省了 - 这,即使你不使用它,您已申请获得与 CLIENT_ALL

这我绊倒以及因为第二个是的下的文件的云端储存部分中提到。

如果这不解决您的问题(比如你已经有那些在你的清单),开始最好的地方就是的疑难解答文档部分。

此外,为了获得完整的错误记录应启用调试日志对于游戏助手,如下:

  gameHelper =新GameHelper(这一点,GameHelper.CLIENT_ALL);
 gameHelper.setup(本); gameHelper.enableDebugLog(真); //添加这个(但仅限于调试版本)

So, I guess it'd help to say that I'm using LibGDX.

Code:

package com.fmeg.tapout.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.applifier.impact.android.ApplifierImpact;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.fmeg.tapout.ActionResolver;
import com.fmeg.tapout.TapoutGame;
import com.google.android.gms.games.Games;
import com.google.example.games.basegameutils.GameHelper;
import com.google.example.games.basegameutils.GameHelper.GameHelperListener;

public class AndroidLauncher extends AndroidApplication
    implements GameHelperListener, ActionResolver {

    private static final String EVERPLAY_GAME_ID = "14234";

    private GameHelper gameHelper;

    public AndroidLauncher() {

    }

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

        ApplifierImpact.setDebugMode(false);
        ApplifierImpact.setTestMode(false);
        ApplifierImpact impact = new ApplifierImpact((Activity)this, EVERPLAY_GAME_ID);
        ApplifierImpact.instance.changeActivity(this);

        gameHelper = new GameHelper(this, GameHelper.CLIENT_ALL);
        gameHelper.setup(this);

        initialize(new TapoutGame(impact, this), config);

    }

    @Override
    public void onStart() {
        super.onStart();
//      gameHelper.onStart(this);
    }

    @Override
    public void onStop() {
        super.onStop();
//      gameHelper.onStop();
    }


    @Override
    public void onActivityResult(int request, int response, Intent data) {
        super.onActivityResult(request, response, data);
//      gameHelper.onActivityResult(request, response, data);
    }

    @Override
    public void onSignInFailed() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSignInSucceeded() {
        // TODO Auto-generated method stub

    }

    @Override
    public void unlockAchievement(String achievementID) {
        Games.Achievements.unlock(gameHelper.getApiClient(), achievementID);
    }

    @Override
    public void achivementProgress(String achievementID, int progression) {
        Games.Achievements.increment(gameHelper.getApiClient(), achievementID, progression);
    }

    @Override
    public void submitScoreToLeaderboard(String leaderboardID, int score) {
        Games.Leaderboards.submitScore(gameHelper.getApiClient(), leaderboardID, score);
    }

    @Override
    public void displayLeaderboard(String leaderboardID) {
        startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), leaderboardID), 101);
    }

    @Override
    public void shareScore(String challenge, int score) {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, "I managed to get "+score+" taps during the " + challenge + " while playing Tap Out! How fast are you? Challenge the world. #FMEGTapout Download Now! http://bit.ly/FMEGTapout");
        sendIntent.setType("text/plain");
        startActivity(sendIntent);
    }

}

The above code compiles and runs fine, however as soon as you attempt to use one of the google play services, such as updating a score or an achievement you get this error:

05-24 01:19:11.413: E/AndroidRuntime(24280): FATAL EXCEPTION: Timer-0
05-24 01:19:11.413: E/AndroidRuntime(24280): java.lang.IllegalStateException: GoogleApiClient is not connected yet.
05-24 01:19:11.413: E/AndroidRuntime(24280):    at com.google.android.gms.internal.fq.a(Unknown Source)
05-24 01:19:11.413: E/AndroidRuntime(24280):    at com.google.android.gms.common.api.b.b(Unknown Source)
05-24 01:19:11.413: E/AndroidRuntime(24280):    at com.google.android.gms.games.internal.api.AchievementsImpl.unlock(Unknown Source)
05-24 01:19:11.413: E/AndroidRuntime(24280):    at com.fmeg.tapout.android.AndroidLauncher.unlockAchievement(AndroidLauncher.java:77)
05-24 01:19:11.413: E/AndroidRuntime(24280):    at com.fmeg.tapout.screens.GameOver.handleAchievements(GameOver.java:98)
05-24 01:19:11.413: E/AndroidRuntime(24280):    at com.fmeg.tapout.screens.GameOver.<init>(GameOver.java:36)
05-24 01:19:11.413: E/AndroidRuntime(24280):    at com.fmeg.tapout.screens.Tick.run(Play.java:85)
05-24 01:19:11.413: E/AndroidRuntime(24280):    at java.util.Timer$TimerImpl.run(Timer.java:284)

Also in AndroidLauncher.java if you uncomment the following lines

@Override
public void onStart() {
    super.onStart();

// gameHelper.onStart(this); }

@Override
public void onStop() {
    super.onStop();

// gameHelper.onStop(); }

@Override
public void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);

// gameHelper.onActivityResult(request, response, data); }

The application will crash upon startup, and this is how it's supposed to be called anyway according to the references I've been using. The crash error shows:

05-24 01:32:19.854: E/AndroidRuntime(25552): FATAL EXCEPTION: main
05-24 01:32:19.854: E/AndroidRuntime(25552): java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
05-24 01:32:19.854: E/AndroidRuntime(25552):    at com.google.android.gms.internal.ff$h.b(Unknown Source)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at com.google.android.gms.internal.ff$h.a(Unknown Source)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at com.google.android.gms.internal.ff$b.eN(Unknown Source)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at com.google.android.gms.internal.ff$a.handleMessage(Unknown Source)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at android.os.Looper.loop(Looper.java:137)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at android.app.ActivityThread.main(ActivityThread.java:5455)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at java.lang.reflect.Method.invokeNative(Native Method)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at java.lang.reflect.Method.invoke(Method.java:525)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
05-24 01:32:19.854: E/AndroidRuntime(25552):    at dalvik.system.NativeStart.main(Native Method)


https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/tutorial-libgdx-gameservices-android/src/com/theinvader360/tutorial/libgdx/gameservices/MainActivity.java

https://developers.google.com/games/services/android/leaderboards

解决方案

Your code looks fine. However, since you are using CLIENT_ALL (meaning all Play Games services) you will need to add both of the following to your manifest:

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

The first is required to sign-in, and the second is required for cloud saves - which, even if you don't use it, you have requested access to with CLIENT_ALL.

This tripped me up as well because the second one is only mentioned under the Cloud Save section of the documentation.

If this does not fix your problem (i.e. you already have those in your manifest), the best place to start is the Troubleshooting section of the documentation.

Also, to get full error logging you should enable the debug log for the game helper, as follows:

 gameHelper = new GameHelper(this, GameHelper.CLIENT_ALL);
 gameHelper.setup(this);

 gameHelper.enableDebugLog(true);   // add this (but only for debug builds)

这篇关于GameHelper崩溃的应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆