【发布时间】:2015-03-27 04:44:15
【问题描述】:
我使用了来自 developer.android.com/training 的谷歌演示示例 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
有人看到我的错误吗?
【问题讨论】:
-
尝试使用与在 Play 商店注册的 Google 帐户不同的 Google 帐户进行测试?我记得看到很多这样的访问问题都是这样解决的
-
我尝试使用与我公司不同的 Google 帐户,但出现同样的错误。
-
我不知道在创建游戏服务时,您必须提供您要用来签署apk的密钥的指纹。因此,提供的指纹与来自签名密钥的指纹不同。我现在已经考虑过这个并在另一个项目中更改了这个,同样的 10004 错误。
标签: android google-play-services