GoogleApiClient app crash from Android on connect ()

my app crashes with no error message in googleApiClient.connect()

. It never hits onConnectionFailed. Here's what I have:

at MainActivity

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

    public static final int REQUEST_LEADERBOARD = 1;
    public static int SCREEN_WIDTH;
    public static int SCREEN_HEIGHT;
    private GoogleApiClient googleApiClient;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        SCREEN_WIDTH = metrics.widthPixels;
        SCREEN_HEIGHT = metrics.heightPixels;

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

    public void newGame(View view) {
        Intent intent = new Intent(MainMenu.this, Game.class);
        startActivity(intent);
        finish();
    }

    public void highScore(View view) {
        if (isSignedIn()) {
            startActivityForResult(Games.Leaderboards.getLeaderboardIntent(googleApiClient,
                    String.valueOf(R.string.leaderboard_id)), REQUEST_LEADERBOARD);
        }
        else {
            System.out.println("not sign in");
        }
    }

    @Override
    public void onConnected(Bundle bundle) {

    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        System.out.println("failed");
    }

    @Override
    protected void onStart() {
        super.onStart();
        googleApiClient.connect(); //here it crashed
    }

    private boolean isSignedIn() {
        return (googleApiClient != null && googleApiClient.isConnected());
    }
}

      

What I've done:

I created a signed APK, I have a sha1 key. I have published an alpha testing app.

manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="my.package"
          android:versionCode="2"
          android:versionName="1.1">
    <uses-sdk android:minSdkVersion="1"/>



    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"
                 android:theme="@style/Theme.AppCompat.NoActionBar"
                 android:isGame="true" >

        <meta-data
                android:name="com.google.android.gms.games.APP_ID"
                android:value="@string/app_id" />
        <meta-data
                android:name="my.package.version"
                android:value="com.google.android.gms.version" />


        <activity android:name=".activities.MainMenu">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".activities.Game"/>
        <activity android:name=".activities.GameOver"/>
        <activity android:name=".activities.HighScore"/>
    </application>
</manifest>

      

I am testing it on a device with Google Play service installed. could you help me?

+3


source to share


2 answers


You must add permission to access your manifest.

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

      



If you need more help, you should show the stacktrace error.

Hope this helps you!

0


source


The solution is simple

<meta-data
    android:name="my.package.version"
    android:value="com.google.android.gms.version" />

      

- nonsense.



it should be:

<meta-data
     android:name="com.google.android.gms.version"
     android:value="@integer/google_play_services_version" />

      

0


source







All Articles