0

I am new in Android's Google Play Service development. I am following an example Type-a-Number Challenge which demonstrate Sign-In, Achievements, and Leaderboards. Link here. Everything works well except When I Cancel the Sign In flow while choosing an account by Clicking to "Cancel" button, my app crashes.

Error logs:

03-23 06:30:20.039: E/AndroidRuntime(28837): java.lang.NoClassDefFoundError: com.google.android.gms.R$string
03-23 06:30:20.039: E/AndroidRuntime(28837):    at com.google.android.gms.common.GooglePlayServicesUtil.b(Unknown Source)
03-23 06:30:20.039: E/AndroidRuntime(28837):    at com.google.android.gms.common.GooglePlayServicesUtil.a(Unknown Source)
03-23 06:30:20.039: E/AndroidRuntime(28837):    at com.google.android.gms.common.GooglePlayServicesUtil.getErrorDialog(Unknown Source)
03-23 06:30:20.039: E/AndroidRuntime(28837):    at com.softhinkers.games.basegameutils.BaseGameUtils.showActivityResultError(BaseGameUtils.java:140)
03-23 06:30:20.039: E/AndroidRuntime(28837):    at com.softhinkers.multiplayergamedemo.MainActivity.onActivityResult(MainActivity.java:430)

BaseGameUtils.showActivityResultError is shown below:

    public static void showActivityResultError(Activity activity, int        requestCode, int actResp, int errorDescription) {
    if (activity == null) {
        Log.e("BaseGameUtils", "*** No Activity. Can't show failure dialog!");
        return;
    }
    Dialog errorDialog;

    switch (actResp) {
        case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.app_misconfigured));
            break;
        case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.sign_in_failed));
            break;
        case GamesActivityResultCodes.RESULT_LICENSE_FAILED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.license_failed));
            break;
        default:
            // *******Error Occurs here**********
            //No meaningful Activity response code, so generate default Google
            // Play services dialog
            final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
            errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                    activity, requestCode, null);

            if (errorDialog == null) {
                // get fallback dialog
                Log.e("BaseGamesUtils",
                        "No standard error dialog available. Making fallback dialog.");
                errorDialog = makeSimpleDialog(activity, activity.getString(errorDescription));
            }
    }

    errorDialog.show();
}

MainActivity.OnActivityResultError is shown below:

protected void onActivityResult(int requestCode, int resultCode,
        Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (requestCode == RC_SIGN_IN) {
        mSignInClicked = false;
        mResolvingConnectionFailure = false;
        if (resultCode == RESULT_OK) {
            mGoogleApiClient.connect();

            //*****Error occurs here*****
        } else {

                BaseGameUtils.showActivityResultError(this, requestCode,
                        resultCode, R.string.signin_other_error);
        }
    }
    // added from Android game
    if (!mGoogleApiClient.isConnecting()) {
        // If Google Play services resolved the issue with a dialog then
        // onStart is not called so we need to re-attempt connection
        // here.
        mGoogleApiClient.connect();
    }
}

I would be thankful if anyone help me and show me how to correct it.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
  • @PM 77-1: Thanks for editing my question. Can you please help me with my problem :( – Adarsh Maurya Mar 23 '15 at 01:44
  • It seems that it can't find compiled strings for error messages. Did you keep all xml files at their original locations? Particularly, `strings.xml`? – PM 77-1 Mar 23 '15 at 02:42
  • @PM 77-1 Yes, I did it. I followed the logcat. The error lies with BaseGameUtils.showActivityResultError(this, requestCode, resultCode, R.string.signin_other_error); of BaseGameUtils class with the default option of Switch case. It is not able to caught the exception when "Choose an account" dialog box which pops out after mGoogleApiClient.connect() is "Cancelled". I tried putting it in Try-Catch block. But it did not worked. – Adarsh Maurya Mar 23 '15 at 03:16
  • I found the answer to my question. If I comment out the /* BaseGameUtils.showActivityResultError(this, requestCode, resultCode, R.string.signin_other_error);*/ the unknown caused by Cancelling the "choose an account" dialog box does not get thrown and the app does not crashes. – Adarsh Maurya Mar 24 '15 at 15:38
  • Check this link http://stackoverflow.com/questions/20148526/google-game-services-sign-in-issue-fails-first-attempt-successful-second – Adarsh Maurya Mar 31 '15 at 10:48

0 Answers0