Google PlayPlayServices(游戏)上的Android崩溃连接

时间:2016-04-03 21:40:33

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

我在10小时左右解决这个问题,我无法弄清楚我做错了什么......

Fatal Exception

E/AndroidRuntime: FATAL EXCEPTION: main
   Process: onl.deepspace.zoorallye, PID: 13256
   java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
   at com.google.android.gms.common.internal.zzj$zza.zzc(Unknown Source)
   at com.google.android.gms.common.internal.zzj$zza.zzw(Unknown Source)
   at com.google.android.gms.common.internal.zzj$zzc.zzqN(Unknown Source)
   at com.google.android.gms.common.internal.zzj$zzb.handleMessage(Unknown Source)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5569)
   at java.lang.reflect.Method.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:931)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:726)

Log未提供任何重要信息


我在环顾谷歌,我可以修复一些错误。但是App 总是在这里崩溃:

  

achievements.googleApiClient.connect();

MainActivity(重要部分):

Achievements achievements;

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

    ...

    //Init Achievements
    achievements = new Achievements(this);
    achievements.googleApiClient.connect(); //**AppCrash**
}

@Override
protected void onStart() {
    super.onStart();
}

@Override
protected void onStop() {
    super.onStop();
    achievements.googleApiClient.disconnect();
}    

Achievements.java:

public class Achievements implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks{

public GoogleApiClient googleApiClient;
private Activity activity;

public Achievements(Activity activity){
    this.activity = activity;

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

private void signIn(GoogleApiClient signinClient) {
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(signinClient);
    activity.startActivityForResult(signInIntent, 0);
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    if(connectionResult.getErrorCode() == ConnectionResult.SIGN_IN_REQUIRED){
        signIn(Tools.getSigninClient(activity));
    }
    Toast.makeText(activity, connectionResult.getErrorMessage(), Toast.LENGTH_SHORT).show();
    Log.e(Const.LOGTAG, connectionResult.getErrorMessage());
}

@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.i(Const.LOGTAG, "Play Service (Games) Connected");
}

@Override
public void onConnectionSuspended(int i) {
}
}

的AndroidManifest.xml:

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

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/appicon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.Drawer"></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.onl.deepspace.zoorallye"
        android:value="@string/google_app_id" />

</application>

2 个答案:

答案 0 :(得分:1)

在社区周围查找类似帖子并找到此answer,请查看。要直截了当地说,我认为这个问题的原因在于你的AndroidManifest.xml。正如答案中所提到的,应该添加<meta-data>标签,你的标签是,但名称不同。它显示为:

android:name="com.google.android.gms.games.onl.deepspace.zoorallye"

在上面的答案中,它显示:

android:name="com.google.android.gms.games.APP_ID"

去了Google Quickstart samples并注意到所有标签都像上面那样。您的代码中没有看到任何导致问题的内容。希望这可以帮助。祝你好运。

答案 1 :(得分:0)

I believe this might be related to missing the com.google.android.gms.games.APP_ID metadata element in your AndroidManifest.xml

It looks like a typo (you replaced APP_ID with your package name?). It should be: <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" />

You can refer to TypeANumber basic sample's AndroidManifest.xml https://github.com/playgameservices/android-basic-samples/blob/master/BasicSamples/TypeANumber/src/main/AndroidManifest.xml#L41