Google Api Client会因未知错误导致崩溃

时间:2017-07-01 16:32:21

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

我从网站上获得了一个示例应用,以了解Google Games Signin。应用程序在启动时崩溃。这是我正在使用的网站的link。这是唯一活动的Java类。它应该在应用程序打开时提示登录。

import android.os.CountDownTimer;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.firebase.analytics.FirebaseAnalytics;

public class MainActivity extends AppCompatActivity{
    private FirebaseAnalytics mFirebaseAnalytics;
    private Button mainButton;
    private TextView scoreView;
    private TextView timeView;

    private int score = 0;
    private boolean playing = false;

    GoogleApiClient apiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    mainButton = (Button)findViewById(R.id.main_button);
    scoreView = (TextView)findViewById(R.id.score_view);
    timeView = (TextView)findViewById(R.id.time_view);




    apiClient = new GoogleApiClient.Builder(this)
            .addApi(Games.API)
            .addScope(Games.SCOPE_GAMES)
            .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                    Toast.makeText(getApplicationContext(), "Could not Sign in", Toast.LENGTH_SHORT).show();
                }
            })
            .build();



    mainButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(!playing) {
                // The first click
                playing = true;
                mainButton.setText("Keep Clicking");

                // Initialize CountDownTimer to 60 seconds
                new CountDownTimer(60000, 1000) {
                    @Override
                    public void onTick(long millisUntilFinished) {
                        timeView.setText("Time remaining: " + millisUntilFinished/1000);
                    }

                    @Override
                    public void onFinish() {
                        playing = false;
                        timeView.setText("Game over");
                        mainButton.setVisibility(View.GONE);
                    }
                }.start();  // Start the timer
            } else {
                // Subsequent clicks
                score++;
                scoreView.setText("Score: " + score + " points");
            }
        }
    });
  }

}

以下是日志:

07-01 11:20:48.616 31570-31570/carsquared.mylittlegame E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     Process: carsquared.mylittlegame, PID: 31570
                                                                     Theme: themes:{com.teslacoilsw.launcher=overlay:system, com.google.android.apps.nexuslauncher=overlay:org.cyanogenmod.hexolibre, default=overlay:org.cyanogenmod.hexolibre, iconPack:system, fontPkg:system, com.android.systemui=overlay:org.cyanogenmod.hexolibre, com.android.systemui.navbar=overlay:system}
                                                                     java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
                                                                         at com.google.android.gms.common.internal.zzf$zza.zzc(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzf$zza.zzu(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzf$zze.zzxa(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzf$zzd.handleMessage(Unknown Source)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5461)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                         at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)

2 个答案:

答案 0 :(得分:0)

您可以参考此thread。在AndroidManifest.xml下的<application> tag,添加meta-data android:name="com.google.android.gms.games.APP_ID"

如果您还在游戏中使用Cloud Save服务,则还必须通过在<application>标记范围内添加以下元数据标记来更新应用程序的AndroidManifest.xml。 meta-data android:name="com.google.android.gms.appstate.APP_ID"

答案 1 :(得分:0)

确保所有Google Play服务依赖项与我的修复版本相同