连接到Google Play服务时出错

时间:2016-08-12 11:58:46

标签: android

您好我正在使用Google Play游戏服务开发基于回合制的多人在线Android应用。我已根据Google Play游戏服务指南中的说明在Google开发者控制台上配置了我的应用。我也在我的项目中导入BasicGameUtils库。但是当我尝试在我的应用程序中登录谷歌播放服务时,我总是会收到以下错误。

应用程序配置不正确。检查包名称和签名证书是否与在Developer Console中创建的客户端ID匹配。此外,如果申请尚未发布,请检查您尝试登录的帐户是否列为测试人员帐户。有关详细信息,请参阅日志。

请有人知道解决方案吗?。

这是我的manifest.xml

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/app_id" />
        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
        <activity android:name="com.appsclubx.project.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

这是我的MainActivity

public class MainActivity extends Activity implements   
GoogleApiClient.ConnectionCallbacks, 
GoogleApiClient.OnConnectionFailedListener 

{

private GoogleApiClient mGoogleApiClient;

private static int RC_SIGN_IN = 9001;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInflow = true;
private boolean mSignInClicked = false;
public Button clk,outbtn;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();
    clk= (Button) findViewById(R.id.click);
    clk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSignInClicked = true;
            mGoogleApiClient.connect();
        }
    });
    outbtn= (Button) findViewById(R.id.out1);
    outbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSignInClicked = false;
            Games.signOut(mGoogleApiClient);
            mGoogleApiClient.disconnect();
        }
    });
    System.out.println("Main activity oncreate function called");
}
@Override
public void onConnected(Bundle bundle) {

    Log.d("Error","User is sign in");

}
@Override
public void onConnectionSuspended(int i) {
    mGoogleApiClient.connect();
}
@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
    Log.d("Error","Google Api client connection on start");
}
@Override
protected void onStop() {
    super.onStop();
    mGoogleApiClient.disconnect();
    Log.d("Error =","Google Api client connection on Stop");
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    System.out.println("Google Api client connection failed");

    Log.d("Error",""+connectionResult.getErrorCode()+""+connectionResult.getErrorMessage());
    if (mResolvingConnectionFailure) {
        // already resolving
        return;
    }
    // if the sign-in button was clicked or if auto sign-in is enabled,
    // launch the sign-in flow
    if (mSignInClicked || mAutoStartSignInflow) {
        mAutoStartSignInflow = false;
        mSignInClicked = false;
        mResolvingConnectionFailure = BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient,
                connectionResult, RC_SIGN_IN, getString(R.string.signin_other_error));

        // Attempt to resolve the connection failure using BaseGameUtils.
        // The R.string.signin_other_error value should reference a generic
        // error string in your strings.xml file, such as "There was
        // an issue with sign-in, please try again later."
    }
    Log.d("Switch =","Switch to screen");
}

protected void onActivityResult(int requestCode, int resultCode,
                                Intent intent) {
    if (requestCode == RC_SIGN_IN) {
        mSignInClicked = false;
        mResolvingConnectionFailure = false;
        if (resultCode == RESULT_OK) {
            mGoogleApiClient.connect();
        } else {
            // Bring up an error dialog to alert the user that sign-in
            // failed. The R.string.signin_failure should reference an error
            // string in your strings.xml file that tells the user they
            // could not be signed in, such as "Unable to sign in."
            BaseGameUtils.showActivityResultError(this,
                    requestCode, resultCode, R.string.signin_other_error);
        }
    }
}}

这是我的成绩构建

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.appsclubx.project"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 3
    versionName "1.1"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    
        'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile "com.google.android.gms:play-services-games:9.4.0"
compile "com.google.android.gms:play-services-plus:9.4.0"

compile project(':BaseGameUtils')
}

1 个答案:

答案 0 :(得分:0)

验证您的应用程序以连接到Google Play服务。从URL获取帮助: https://developers.google.com/drive/android/auth