Android - “Connecting to Google Play” still gives Error Code 4?

别等时光非礼了梦想. 提交于 2019-12-02 22:29:35

问题


I'm still a bit new to the Google APIs and the GoogleApiClient class, so I followed this tutorial hoping to get set up enough to display a leaderboard.

At the moment I've implemented this code into my game activity.

public void onConnectionFailed(ConnectionResult arg0) {
    Log.d("fes", "error " + arg0.getErrorCode());
    if (!isGooglePlayIntentOpen && arg0.hasResolution()) {
        try {
            isGooglePlayIntentOpen = true;
            startIntentSenderForResult(arg0.getResolution()
                    .getIntentSender(), 10, null, 0, 0, 0);
        } catch (SendIntentException ex) {
            isGooglePlayIntentOpen = false;
            this.getApiClient().connect();
        }
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 10) {
        isGooglePlayIntentOpen = false;
        if (!this.getApiClient().isConnecting() && !this.getApiClient().isConnected()) {
            this.getApiClient().connect();
        }
    }
}

This does, in fact, pop up a small intent that says "Connecting to Google Play", followed by a selection of an account. Which is as expected.

However, every time onConnectionFailed gets called, the error code appears to be 4.

According to ConnectionResult, 4 means Sign-in Required.

What gives? Even after attempting to "sign in" on multiple accounts, I still get the same error code. Do I somehow need to pass the sign-in result to my GoogleApiClient?

Cheers!


回答1:


If it connects and works fine in the local build, but the version you download from the Play Store doesn't work(it gives sign in error), this is how you fix it. When you uploaded your APK you used your SHA1 for the Uploaded Version. Google gives you a different SHA1 AFTER YOU UPLOAD YOUR APK. You need to input this NEW SHA1 into your Credentials.


Follow these steps:

  1. Go to Google Developer Console
  2. Click All Applications > Your Application
  3. Go to Release Management > App Signing
  4. Notice there is an "Upload Certificate" and an "App Signing Certificate".
  5. Copy the SHA1 from the APP SIGNING CERTIFICATE. (After all that keystore rigmorale, they fail to mention this part in documentation!)
  6. Create a new connected app in Game Services and then PASTE THE SHA1 FROM THE APP SIGNING CERTIFICATE HERE AND BE SURE YOUR PACKAGE NAME IS CORRECT.

Everything should work now! I don't understand why this is not documented clearly.




回答2:


Make sure that you use the SHA1 key.

The command "keytool -list -keystore [path to debug keystore]" may display a SHA-256 key.

To get your SHA1 key you can follow these steps:

  1. Open your project
  2. Click on "Gradle" (on the right side)
  3. Choose your module
  4. Tasks -> android -> (double click) signingReport

image: get your SHA1 key




回答3:


Sounds like your game may not be setup correctly in the play game console. Some things to check:

  1. The appId in your application matches the app id in the console.

  2. There is a linked Android application to your game.

  3. The linked application has the package configured to match the package in your AndroidManifest.xml
  4. The linked application is authorized and has the SHA1 fingerprint that matches the keystore you are using to sign your application.
  5. Make sure the user id you are using to sign-in is in the testers list for your game.
  6. If you are using SavedGamesAPI, make sure it is enabled on the console.

You can review the instructions to do all these things at https://developers.google.com/games/services/android/quickstart#step_2_set_up_the_game_in_the_dev_console




回答4:


Fixed.

After getting countless SIGN_IN_REQUIRED I managed to allocate a lot of RESULT_APP_MISCONFIGURED.

The solution? It's very important to add a ProGuard exception, as described here.




回答5:


Even though it's four years since the original question was asked, I'd like to add my 2c worth as I had the same problem and none of the above advice solved it for me.

What solved it for me was realising that you need an SHA1 fingerprint for your app when it has been released into the Google Play Store and a different one for when you are debugging. The first is created automatically when you set up your app in the Google Play Console and is unique but it's never used until you release your app. The debug one you have to create yourself and it's the same for all the apps you are debugging. Details of the credentials are stored in your Google API Console.

To sum up, every app you have that uses Google Play Services should have two OAuth Client IDs in the Google API Console one for debug and one for the released version. How to so this is explained adequately in the documentation here.



来源:https://stackoverflow.com/questions/28919040/android-connecting-to-google-play-still-gives-error-code-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!