Google Play服务resultCode = 10004

时间:2015-01-28 10:16:43

标签: android google-play-services

我使用了developer.android.com/training中的google演示示例TypeANumber。我在play.google.com开发者控制台中正确配置了应用程序,甚至发布了它,在开发者控制台中正确配置了游戏服务TypeANumber并链接了之前提到的应用程序,甚至发布了服务,我仍然继续得到resultCode 10004代表

  

public static final int RESULT_APP_MISCONFIGURED   当游戏不正确时,结果代码会发送回调用Activity   配置为访问游戏服务。开发人员应检查日志以获取更多详细信息。   常数值:10004(0x00002714)

使用过的代码是:

package com.sitewalk.typeanumber;

import android.accounts.AccountManager;
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.auth.GoogleAuthUtil;
import com.google.android.gms.common.AccountPicker;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;

import com.google.android.gms.games.Games;

public class GooglePlayServicesActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    private static final String TAG = "GooglePlayServicesActivity";
    private static final String KEY_IN_RESOLUTION = "is_in_resolution";
    private static final String DIALOG_ERROR = "dialog_error";
    private static final int REQUEST_RESOLVE_ERROR = 1001;
    private GoogleApiClient mGoogleApiClient;
    private boolean mIsInResolution;
    private boolean mResolvingError=false;
    private static final String STATE_RESOLVING_ERROR = "resolving_error";

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

        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Games.API)
                    .addScope(Games.SCOPE_GAMES)
                            // Optionally, add additional APIs and scopes if required.
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (!mResolvingError) {  // more about this later
            mGoogleApiClient.connect();
        }
    }

    @Override
    protected void onStop() {
        if (mGoogleApiClient != null) {
            mGoogleApiClient.disconnect();
        }
        super.onStop();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean(KEY_IN_RESOLUTION, mIsInResolution);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_RESOLVE_ERROR) {
            mResolvingError = false;
            if (resultCode == RESULT_OK) {
                // Make sure the app is not already connected or attempting to connect
                if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
                    mGoogleApiClient.connect();
                }
            }
        }
    }

    private void retryConnecting() {
        mIsInResolution = false;
        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        Log.i(TAG, "GoogleApiClient connected");
        startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient), 5638676);
    }

    @Override
    public void onConnectionSuspended(int cause) {
        Log.i(TAG, "GoogleApiClient connection suspended");
        retryConnecting();
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        if (mResolvingError) {
            // Already attempting to resolve an error.
            return;
        } else if (result.hasResolution()) {
            try {
                mResolvingError = true;
                result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
            } catch (SendIntentException e) {
                // There was an error with the resolution intent. Try again.
                mGoogleApiClient.connect();
            }
        } else {
            // Show dialog using GooglePlayServicesUtil.getErrorDialog()
            showErrorDialog(result.getErrorCode());
            mResolvingError = true;
        }
    }

    /* Creates a dialog for an error message */
    private void showErrorDialog(int errorCode) {
        // Create a fragment for the error dialog
        ErrorDialogFragment dialogFragment = new ErrorDialogFragment();
        // Pass the error that should be displayed
        Bundle args = new Bundle();
        args.putInt(DIALOG_ERROR, errorCode);
        dialogFragment.setArguments(args);
        dialogFragment.show(getFragmentManager(), "errordialog");
    }

    /* Called from ErrorDialogFragment when the dialog is dismissed. */
    public void onDialogDismissed() {
        mResolvingError = false;
    }

    /* A fragment to display an error dialog */
    public static class ErrorDialogFragment extends DialogFragment {
        public ErrorDialogFragment() { }

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Get the error code and retrieve the appropriate dialog
            int errorCode = this.getArguments().getInt(DIALOG_ERROR);
            return GooglePlayServicesUtil.getErrorDialog(errorCode,
                    this.getActivity(), REQUEST_RESOLVE_ERROR);
        }

        @Override
        public void onDismiss(DialogInterface dialog) {
            ((GooglePlayServicesActivity)getActivity()).onDialogDismissed();
        }
    }
}

以及正确的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sitewalk.typeanumber" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".GooglePlayServicesActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data android:name="com.google.android.gms.games.APP_ID"
                   android:value="@string/app_id" />
    </application>

</manifest>

使用正确的APP-ID(数字后检查数字), 以及包含播放服务依赖项的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.sitewalk.typeanumber"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 2
        versionName "1.1"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:6.5.87'
}

Logcat没有告诉我有关10004 codeResult的任何信息:

01-28 11:10:54.735  31182-31182/com.sitewalk.typeanumber D/dalvikvm﹕ Late-enabling CheckJNI
01-28 11:10:54.755  31182-31188/com.sitewalk.typeanumber D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
01-28 11:10:55.055  31182-31182/com.sitewalk.typeanumber I/System.out﹕ Sending WAIT chunk
01-28 11:10:55.055  31182-31182/com.sitewalk.typeanumber W/ActivityThread﹕ Application com.sitewalk.typeanumber is waiting for the debugger on port 8100...
01-28 11:10:55.775  31182-31188/com.sitewalk.typeanumber I/dalvikvm﹕ Debugger is active
01-28 11:10:55.865  31182-31182/com.sitewalk.typeanumber I/System.out﹕ Debugger has connected
01-28 11:10:55.865  31182-31182/com.sitewalk.typeanumber I/System.out﹕ waiting for debugger to settle...
01-28 11:10:56.075  31182-31182/com.sitewalk.typeanumber I/System.out﹕ waiting for debugger to settle...
01-28 11:10:56.275  31182-31182/com.sitewalk.typeanumber I/System.out﹕ waiting for debugger to settle...
01-28 11:10:56.475  31182-31182/com.sitewalk.typeanumber I/System.out﹕ waiting for debugger to settle...
01-28 11:10:56.675  31182-31182/com.sitewalk.typeanumber I/System.out﹕ waiting for debugger to settle...
01-28 11:10:56.875  31182-31182/com.sitewalk.typeanumber I/System.out﹕ waiting for debugger to settle...
01-28 11:10:57.075  31182-31182/com.sitewalk.typeanumber I/System.out﹕ waiting for debugger to settle...
01-28 11:10:57.275  31182-31182/com.sitewalk.typeanumber I/System.out﹕ waiting for debugger to settle...
01-28 11:10:57.475  31182-31182/com.sitewalk.typeanumber I/System.out﹕ debugger has settled (1340)
01-28 11:10:57.755  31182-31182/com.sitewalk.typeanumber W/PopupManager﹕ You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.
01-28 11:10:57.835  31182-31182/com.sitewalk.typeanumber I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
    OpenGL ES Shader Compiler Version: E031.24.00.07
    Build Date: 04/07/14 Mon
    Local Branch: au011
    Remote Branch:
    Local Patches:
    Reconstruct Branch:
01-28 11:10:57.865  31182-31182/com.sitewalk.typeanumber D/OpenGLRenderer﹕ Enabling debug mode 0
01-28 11:11:01.435  31182-31182/com.sitewalk.typeanumber I/Choreographer﹕ Skipped 211 frames!  The application may be doing too much work on its main thread.
01-28 11:11:01.665  31182-31182/com.sitewalk.typeanumber I/ActivityManager﹕ Timeline: Activity_idle id: android.os.BinderProxy@42e3b748 time:437201118
01-28 11:11:10.835  31182-31182/com.sitewalk.typeanumber I/ActivityManager﹕ Timeline: Activity_idle id: android.os.BinderProxy@42e3b748 time:437210285

我只有一个事件日志:

11:10:34 Gradle build finished in 5 sec

有人看到我的错误吗?

2 个答案:

答案 0 :(得分:1)

我没有将游戏服务与设置了调试密钥的应用程序相关联。 您必须将您的服务两次与您的应用程序相关联,一次使用发布密钥指纹将您的软件包名称链接,并使用调试密钥指纹将您的软件包名称一次与 https://developers.google.com/games/services/console/enabling#c_specify_client_id_settings

有一个类似的问题: Google Play Games - Application in alpha/beta test - Error 10004 at sign-in RESULT APP MISCONFIGURED

答案 1 :(得分:0)

注意 - 如果您在一台计算机上进行开发,现在切换到另一台计算机,则debug.keystore将会有所不同,因此您需要一个新的链接应用程序,因为它们的SHA1不同。

不确定这是不是你的情况,但这是我10004的原因。