0

I've got a sample app from a website to learn about Google Games Signin. The App crashes on start. Here's the link to the website I'm using. Here is the Java class of the only Activity. It is supposed to prompt a signin when the application is opened.

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");
            }
        }
    });
  }

}

And here's the logs:

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)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Carter Ray
  • 151
  • 1
  • 9

2 Answers2

0

You may refer with this thread. In AndroidManifest.xml under the <application> tag, add meta-data android:name="com.google.android.gms.games.APP_ID".

If you also use Cloud Save service in your game you also must to update your application's AndroidManifest.xml by adding the following meta-data tag inside <application> tag scope. meta-data android:name="com.google.android.gms.appstate.APP_ID"

abielita
  • 13,147
  • 2
  • 17
  • 59
0

Ensure all google play service dependencies are of same version that was the fix for me

Samuel Moshie
  • 570
  • 1
  • 5
  • 20