Android - Google Play Service, Game Client, Run time Error

浪尽此生 提交于 2019-12-08 07:35:24

问题


I have checked a few different questions already like this

I am trying to implement a Google sign in and have been referring to https://developers.google.com/games/services/training/signin/ but cannot figure out how to resolve this error

I currently have the following meta data in my Manifest file

      <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"/>

My LogCat error looks like:

- 04-01 15:25:28.461: E/AndroidRuntime(30017): FATAL EXCEPTION: main
- 04-01 15:25:28.461: E/AndroidRuntime(30017): java.lang.IllegalStateException: A fatal   developer error has occurred. Check the logs for further information.
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at com.google.android.gms.internal.eh$h.b(Unknown Source)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at com.google.android.gms.internal.eh$h.a(Unknown Source)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at com.google.android.gms.internal.eh$b.ec(Unknown Source)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at com.google.android.gms.internal.eh$a.handleMessage(Unknown Source)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at android.os.Handler.dispatchMessage(Handler.java:99)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at android.os.Looper.loop(Looper.java:137)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at android.app.ActivityThread.main(ActivityThread.java:5419)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at java.lang.reflect.Method.invokeNative(Native Method)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at java.lang.reflect.Method.invoke(Method.java:525)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
- 04-01 15:25:28.461: E/AndroidRuntime(30017):  at dalvik.system.NativeStart.main(Native Method)

I am also getting a warning earlier:

- 04-01 15:45:45.408: W/PopupManager(1075): You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.

I'm not sure if this has anything to do with it I've tried overriding and calling in the onCreate()

setViewForPopups()

but eclipse does not show this method exists.

My current MainActivity looks like

public class MainActivity extends BaseGameActivity implements OnClickListener {

boolean mExplicitSignOut = false;
boolean mInSignInFlow = false;

GoogleApiClient mClient;

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

    GameView gameView = (GameView) findViewById(R.id.game);

    GoogleApiClient.Builder builder = 
            new GoogleApiClient.Builder(this);
        builder.addApi(Games.API)
               .addApi(Plus.API)
               .addApi(AppStateManager.API)
               .addScope(Games.SCOPE_GAMES)
               .addScope(Plus.SCOPE_PLUS_LOGIN)
               .addScope(AppStateManager.SCOPE_APP_STATE);
        mClient = builder.build();

}

@Override
protected void onStart() {
    super.onStart();
    if (!mInSignInFlow && !mExplicitSignOut) {
        // auto sign in
        mClient.connect();
    }
}

@Override
public void onSignInFailed() {
    // TODO SignInFailed
    Toast.makeText(this, "Sign in Failed", Toast.LENGTH_LONG).show();

}

@Override
public void onSignInSucceeded() {
    // TODO SignInSucceeded
    Toast.makeText(this, "Sign in Succeeded", Toast.LENGTH_LONG).show();

}

@Override
public void onClick(View v) {
    // TODO onClick
    Toast.makeText(this, "Clicked", Toast.LENGTH_LONG).show();

}
}

回答1:


Make sure that you have all 3 meta-data tags in your manifest file -

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

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

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



回答2:


May be you haven't configured OAuth2 client id in Google Deveopers Console.



来源:https://stackoverflow.com/questions/22795679/android-google-play-service-game-client-run-time-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!