【问题标题】:Google Play Game Services + EmulatorGoogle Play 游戏服务 + 模拟器
【发布时间】:2017-03-01 21:19:28
【问题描述】:

我无法在本机模拟器中连接到 Google Play 游戏服务,但是,相同的 apk 可以在 Bluestacks 中使用。

到目前为止,该应用通过Games.Achievements.getAchievementsIntent 请求用户的成就列表。这些成就已成功显示在 Bluestacks 中,但本机模拟器屏幕仍为空白。

说实话,当 Bluestacks 显示用户的成就(如下所示)时,我感到很惊讶,因为我没有实现任何演示逻辑。

我正在使用 Google Play Services 9.6.1 构建依赖项:

compile 'com.google.android.gms:play-services-games:9.6.1'

模拟器正在使用 API 24 + Google API 运行系统映像

我正在使用 GoogleApiClient 的自动管理实例,它尝试连接但随后失败。我尝试了无数次修复都无济于事。

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

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("onActivityResult", "resultCode = " + resultCode);
    if (resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
        mGoogleApiClient.connect();
    }
}

@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.d("onConnected", "onConnected");
    startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient), MY_REQ_CODE);
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    Log.d("onConnectionFailed", "onConnectionFailed");
    mGoogleApiClient.connect();
}

Android 监视器中的结果:

    Connected to process 7907 on device Nexus_5X_API_24_GApps [emulator-5554]
W/System: ClassLoader referenced unknown path: /data/app/goc.dma.cprach.gameofchairs-1/lib/x86
W/PopupManager: You have not specified a View to use as content view for popups. Falling back to the Activity content view. Note that this may not work as expected in multi-screen environments
D/AutoManageHelper: starting AutoManage for client 0 false false
D/onStart: onStart
D/AutoManageHelper: onStart true {0=com.google.android.gms.internal.zzqa$zza@e9fa141}

                    [ 10-20 03:00:11.990  1490: 1511 D/         ]
                    HostConnection::get() New Host Connection established 0x8c3f9680, tid 1511
W/gralloc_ranchu: Gralloc pipe failed

                  [ 10-20 03:00:12.089  7907: 7907 D/         ]
                  HostConnection::get() New Host Connection established 0xa438dac0, tid 7907
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
D/onConnectionFailed: onConnectionFailed
D/AutoManageHelper: beginFailureResolution for ConnectionResult{statusCode=RESOLUTION_REQUIRED, resolution=PendingIntent{20c0bc3: android.os.BinderProxy@6889c40}, message=null}
D/onActivityResult: resultCode = 0

【问题讨论】:

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


    【解决方案1】:

    我不确定这是否会有所帮助,但我在您的错误日志中注意到它说:

    "You have not specified a View to use as content view for popups."
    

    检查此SO thread 建议:

    使用 setViewForPopUps 方法

     Games.setViewForPopups(getApiClient(), getWindow().getDecorView().findViewById(android.R.id.content));
    

    另一种方法是:

    在您的 mGoogleApiClient 对象中定义 setViewForPopups。

    mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
                .addApi(Games.API).addScope(Games.SCOPE_GAMES)
                .addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
                .setViewForPopups(findViewById(android.R.id.content))
                .build();
    

    查看您的代码,您似乎还没有添加此代码。这是setViewForPopups method的补充阅读。

    【讨论】:

      猜你喜欢
      • 2016-04-11
      • 2015-08-26
      • 2014-02-02
      • 1970-01-01
      • 2013-07-31
      • 2017-09-27
      • 2018-05-09
      • 1970-01-01
      相关资源
      最近更新 更多