无法连接到Google API客户端,GooglePlayServices

时间:2017-09-09 19:52:19

标签: android android-studio google-api google-play-services google-play-games

我试图使用Google Play服务,特别是游戏API,我坚持这一点。

我已经从Google配置并编译了两个样本并在我的设备上运行。它们都运行良好,成就,我在Google Console上配置的排行榜。

所以我想更进一步,从头开始用GPServices制作我自己的应用程序。使用最新稳定的Android Studio 2.3.3和最新的SDK

SDKs

我创建了一个新项目,配置为Google指南,示例向我们展示。

Android Manifest:     

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        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=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

摇篮:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "playservices.workshop.akbolatss.gplayservices"
        minSdkVersion 22
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'

    compile "com.google.android.gms:play-services-games:11.0.4"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

MainActivity

public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    GoogleApiClient googleApiClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        googleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Games.API)
                .addScope(Games.SCOPE_GAMES)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

        googleApiClient.connect();
    }

    @Override
    public void onConnected(@Nullable Bundle bundle) {
        Toast.makeText(this, "onConnected", Toast.LENGTH_LONG).show();
        Log.d("TAG", "onConnected");
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.d("TAG", "onConnectionSuspended");
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        Toast.makeText(this, "onConnectionFailed " + connectionResult.getResolution() + " " + connectionResult.getErrorMessage(), Toast.LENGTH_LONG).show();
        Log.d("TAG", "onConnectionFailed");
    }
}

问题是100%失败。并且日志永远不会告诉出错的地方。我不知道我失踪的地方,看起来浪费时间。如果你有时间,请检查项目,特别是它不能在我的机器上工作

项目链接:https://www.dropbox.com/s/h6wsqlvnhno60g8/GPlayServices.rar?dl=0

示例链接:https://github.com/playgameservices/android-basic-samples

1 个答案:

答案 0 :(得分:0)

您是否获得了特定密钥才能访问API?