简体   繁体   English

Android Google Play游戏服务登录失败并循环播放

[英]Android Google play games services signin failed and looped

I've got a huge problem with google play games services. 我在使用Google Play游戏服务时遇到了很大的问题。 Indeed, in some devices, when I try to launch my game, the api try to connect to the services : the play game window appears, then we saw the loading image (a circle), finally an error message comes in front "Unfortunately, Google Service has stopped". 确实,在某些设备中,当我尝试启动游戏时,api尝试连接到服务:出现游戏窗口,然后我们看到正在加载的图片(一个圆圈),最后在前面出现错误消息“不幸的是, Google服务已停止”。 When we click on OK, the process restart ( the loading image, the message ...). 当我们单击“确定”时,该过程将重新启动(正在加载图像,消息...)。

We use GameHepler to implements Google games service. 我们使用GameHepler实施Google游戏服务。

Here is the class AndroidLauncher : 这是类AndroidLauncher:

public class AndroidLauncher extends AndroidApplication implements
    AdControl, ActionResolver,
    GameHelperListener, MultiplayerInterface, RoomUpdateListener,
    RealTimeMessageReceivedListener, RoomStatusUpdateListener,
    View.OnClickListener, OnInvitationReceivedListener {

protected AdView adView;
private GameHelper gameHelper;
private MonJeu monJeu;

private static final String AD_UNIT_ID = "XXXXXXXXXXXXXXXXXXXXX";

private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;

// Request codes for the UIs that we show with startActivityForResult:
final static int RC_SELECT_PLAYERS = 19070;
final static int RC_INVITATION_INBOX = 19071;
final static int RC_WAITING_ROOM = 19072;

final static int MAIN_SCREEN = 29070;
final static int GAME_SCREEN = 29071;
final static int POPUP_INVIT = 29072;
final static int LOADING_SCREEN = 29073;

// The participants in the currently active game
ArrayList<Participant> mParticipants = null;

String creatorId;

// Room ID where the currently active game is taking place; null if we're
// not playing.
String mRoomId = null;

// My participant ID in the currently active game
String mMyId = null;

// If non-null, this is the id of the invitation we received via the
// invitation listener
String mIncomingInvitationId = null;

// Are we playing in multiplayer mode?
boolean mMultiplayer = false;

protected Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
        case SHOW_ADS: {
            adView.setVisibility(View.VISIBLE);
            break;
        }
        case HIDE_ADS: {
            adView.setVisibility(View.GONE);
            break;
        }
        }
    }
};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create the layout
    RelativeLayout layout = new RelativeLayout(this);

    // Do the stuff that initialize() would do for you
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();


    cfg.numSamples = 5;

    monJeu = new MonJeu(this, this, this);
    View gameView = initializeForView(monJeu, cfg); 
    // Create and setup the AdMob view
    adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(AD_UNIT_ID);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("XXXXXXXXXXXXXXXXXXXXX").build();
    adView.loadAd(adRequest);

    // Add the libgdx view
    layout.addView(gameView);

    // Add the AdMob view
    RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    adParams.addRule(RelativeLayout.CENTER_IN_PARENT);

    layout.addView(adView, adParams);

    // Hook it all up
    setContentView(layout);



    if (gameHelper == null) {
        gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
        gameHelper.enableDebugLog(true);
    }
    gameHelper.setup(this);

}

@Override
public void showAds(boolean show) {}

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

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

@Override
public void onActivityResult(int requestCode, int responseCode,
        Intent intent) {
    super.onActivityResult(requestCode, responseCode, intent);

    switch (requestCode) {
    case RC_SELECT_PLAYERS:

        break;
    case RC_INVITATION_INBOX:

        break;
    case RC_WAITING_ROOM:

        break;

    default:
        gameHelper.onActivityResult(requestCode, responseCode, intent);

    }
}


@Override
public boolean getSignedInGPGS() {
    return gameHelper.isSignedIn();
}

@Override
public void loginGPGS() {
    try {
        runOnUiThread(new Runnable() {
            public void run() {
                gameHelper.beginUserInitiatedSignIn();
            }
        });
    } catch (final Exception ex) {
    }
}

@Override
public void submitScoreGPGS(int score) {}

@Override
public void submitScoreOnlineGPGS(int score) {}

@Override
public void unlockAchievementGPGS(String achievementId) {}

@Override
public void getLeaderboardGPGS() {

    if(getSignedInGPGS())
        startActivityForResult(
            Games.Leaderboards.getLeaderboardIntent(
                    gameHelper.getApiClient(), "XXXXXXXXXXXXXXXXXXXXX"), 100);
    else
        loginGPGS();

}


@Override
public void getAchievementsGPGS() {

    if(getSignedInGPGS())
        startActivityForResult(
            Games.Achievements.getAchievementsIntent(gameHelper
                    .getApiClient()), 100);
    else
        loginGPGS();
}

@Override
public void onSignInFailed() {

}

@Override
public void onSignInSucceeded() {
}

This is the log : 这是日志:

11-12 22:41:48.974: V/ActivityManager(1096): Moving to STOPPED: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} (starting in stopped state)
11-12 22:41:49.624: D/GameHelper(26628): GameHelper: Debug log enabled.
11-12 22:41:49.624: D/GameHelper(26628): GameHelper: Setup: requested clients: 1
11-12 22:41:49.634: D/GameHelper(26628): GameHelper: onStart
11-12 22:41:49.634: D/GameHelper(26628): GameHelper: Connecting client.
11-12 22:41:49.744: V/WindowStateAnimator(1096): performShowLocked: mDrawState=HAS_DRAWN in WindowStateAnimator{4629d260 com.google.android.gms/com.google.android.gms.games.ui.signin.SignInActivity}
11-12 22:41:49.754: I/ActivityManager(1096): Displayed com.google.android.gms/.games.ui.signin.SignInActivity: +781ms
11-12 22:41:49.754: I/ActivityManager(1096): Timeline: Activity_windows_visible id: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} time:522233174
11-12 22:41:49.944: D/GameHelper(26628): GameHelper: onConnectionFailed
11-12 22:41:49.944: D/GameHelper(26628): GameHelper: Connection failure:
11-12 22:41:49.944: D/GameHelper(26628): GameHelper:    - code: SIGN_IN_REQUIRED(4)
11-12 22:41:49.944: D/GameHelper(26628): GameHelper:    - resolvable: true
11-12 22:41:49.944: D/GameHelper(26628): GameHelper:    - details: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{438f22c8: android.os.BinderProxy@438f2268}}
11-12 22:41:49.954: D/GameHelper(26628): GameHelper: onConnectionFailed: WILL resolve because we have below the max# of attempts, 0 < 3
11-12 22:41:49.954: D/GameHelper(26628): GameHelper: onConnectionFailed: resolving problem...
11-12 22:41:49.954: D/GameHelper(26628): GameHelper: resolveConnectionResult: trying to resolve result: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{438f22c8: android.os.BinderProxy@438f2268}}
11-12 22:41:49.954: D/GameHelper(26628): GameHelper: Result has resolution. Starting it.
11-12 22:41:49.954: I/ActivityManager(1096): START u0 {flg=0x4000000 cmp=com.google.android.gms/.games.ui.signin.SignInActivity (has extras)} from pid -1
11-12 22:41:49.964: I/ActivityManager(1096): ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t-1} Support Split:false Is ScreenFull:true
11-12 22:41:50.004: V/ActivityManager(1096): Moving to RESUMED: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} (in existing)
11-12 22:41:50.004: V/ActivityManager(1096): Moving to PAUSING: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608}
11-12 22:41:50.004: D/ActivityManager(1096): resumeTopActivityLocked: Resumed ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608}
11-12 22:41:50.014: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} state=PAUSING
11-12 22:41:50.014: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} state=PAUSING
11-12 22:41:50.044: D/GameHelper(26628): GameHelper: onStop
11-12 22:41:50.044: D/GameHelper(26628): GameHelper: Client already disconnected when we got onStop.
11-12 22:41:50.074: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} state=PAUSING
11-12 22:41:50.094: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} state=PAUSING
11-12 22:41:50.114: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} state=PAUSING
11-12 22:41:50.144: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} state=PAUSING
11-12 22:41:50.154: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} state=PAUSING
11-12 22:41:50.194: V/ActivityManager(1096): Moving to PAUSED: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} (pause complete)
11-12 22:41:50.194: V/ActivityManager(1096): Moving to STOPPING: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} (finish requested)
11-12 22:41:50.204: D/ActivityManager(1096): resumeTopActivityLocked: Restarting ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608}
11-12 22:41:50.204: V/ActivityManager(1096): Moving to RESUMED: ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} (starting new instance)
11-12 22:41:50.204: V/ActivityManager(1096): Moving to PAUSING: ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608}
11-12 22:41:50.214: V/ActivityManager(1096): Moving to FINISHING: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f}
11-12 22:41:50.214: V/ActivityManager(1096): Moving to DESTROYING: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} (destroy requested)
11-12 22:41:50.244: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} state=PAUSING
11-12 22:41:50.244: D/ActivityManager(1096): allPausedActivitiesComplete: r=ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} state=PAUSING
11-12 22:41:50.264: V/ActivityManager(1096): Moving to PAUSED: ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} (pause complete)
11-12 22:41:50.264: V/ActivityManager(1096): Moving to STOPPING: ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} (stop requested)
11-12 22:41:50.294: V/ActivityManager(1096): Moving to DESTROYED: ActivityRecord{43834848 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608 f} (removed from history)
11-12 22:41:50.354: V/ActivityManager(1096): Moving to STOPPED: ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} (stop complete)
11-12 22:41:50.384: I/ActivityManager(1096): Displayed com.google.android.gms/.games.ui.signin.SignInActivity: +179ms (total +188ms)
11-12 22:41:50.384: I/ActivityManager(1096): Timeline: Activity_windows_visible id: ActivityRecord{43ef4e58 u0 com.google.android.gms/.games.ui.signin.SignInActivity t1608} time:522233808
11-12 22:41:50.384: V/WindowStateAnimator(1096): performShowLocked: mDrawState=HAS_DRAWN in WindowStateAnimator{460381b0 com.google.android.gms/com.google.android.gms.games.ui.signin.SignInActivity}

And when we've got the popup error, we can generate a report. 当出现弹出错误时,我们可以生成报告。 And so, this is the strack trace of google play crash : 因此,这是google play crash的痕迹:

在此处输入图片说明

After several days of research, I've finally found the solution. 经过几天的研究,我终于找到了解决方案。

The main problem was the java.lang.outofmemory. 主要问题是java.lang.outofmemory。 This exception was thrown because when the consent screen would appear, google play service load in memory the icon of the application stored in the folder res. 之所以引发此异常,是因为当同意屏幕出现时,Google Play服务会在内存中加载存储在res文件夹中的应用程序图标。 In our case, we've generate the icons of our game with a Photoshop plugin found in internet and the icons were too big. 在我们的案例中,我们使用在Internet上找到的Photoshop插件生成了游戏的图标,并且图标太大。

So we've used this website to generate the new icons : http://makeappicon.com/ wich is more efficient than the photoshop plugin. 因此,我们已经使用该网站生成了新图标: http ://makeappicon.com/,它比photoshop插件更有效。 The new icons are lighter and the exceptions is not longer thrown. 新图标更亮,不再抛出异常。

Hope this solution will help someone else ! 希望此解决方案可以帮助其他人! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM