android - Unity Google Play 服务插件 Social.localUser.Authenticate(...) 应用程序崩溃

标签 android unity-game-engine google-play-services google-play-games

Google Play 服务的 Unity3d 代码。我使用的是 GooglePlayGamesPlugin-0.9.36 和 Unity 5.4

using UnityEngine;
    using System.Collections;
    using UnityEngine.SocialPlatforms;
    using GooglePlayGames;

public class MainGui : MonoBehaviour
{
    private const float FontSizeMult = 0.05f;
    private bool mWaitingForAuth = false;
    private string mStatusText = "Ready.";
    private bool dumpedToken = false;
void Start()
{
    // Select the Google Play Games platform as our social platform implementation
    PlayGamesPlatform.Activate();
}

void OnGUI()
{
    GUI.skin.button.fontSize = (int)(FontSizeMult * Screen.height);
    GUI.skin.label.fontSize = (int)(FontSizeMult * Screen.height);

    GUI.Label(new Rect(20, 20, Screen.width, Screen.height * 0.25f),
              mStatusText);

    Rect buttonRect = new Rect(0.25f * Screen.width, 0.10f * Screen.height,
                      0.5f * Screen.width, 0.25f * Screen.height);
    Rect imageRect = new Rect(buttonRect.x + buttonRect.width / 4f,
                              buttonRect.y + buttonRect.height * 1.1f,
                              buttonRect.width / 2f, buttonRect.width / 2f);

    if (mWaitingForAuth)
    {
        return;
    }

    string buttonLabel;


    if (Social.localUser.authenticated)
    {
        buttonLabel = "Sign Out";
        if (Social.localUser.image != null)
        {
            GUI.DrawTexture(imageRect, Social.localUser.image,
                            ScaleMode.ScaleToFit);
        }
        else {
            GUI.Label(imageRect, "No image available");
        }

        mStatusText = "Ready";

        if (!dumpedToken)
        {
            string token = GooglePlayGames.PlayGamesPlatform.Instance.GetToken();

            Debug.Log("AccessToken = " + token);
            dumpedToken = token != null && token.Length > 0;
        }
    }
    else {
        buttonLabel = "Authenticate";
    }

    if (GUI.Button(buttonRect, buttonLabel))
    {
        if (!Social.localUser.authenticated)
        {
            // Authenticate
            mWaitingForAuth = true;
            mStatusText = "Authenticating...";
            Social.localUser.Authenticate((bool success) =>
            {
                mWaitingForAuth = false;
                if (success)
                {
                    mStatusText = "Welcome " + Social.localUser.userName;
                }
                else {
                    mStatusText = "Authentication failed.";
                }
            });
        }
        else {
            // Sign out!
            mStatusText = "Signing out.";
            ((GooglePlayGames.PlayGamesPlatform)Social.Active).SignOut();
        }
    }
    }
}

当我按下身份验证按钮时,应用程序崩溃。并且 Google Play 服务对话框没有出现。我已经构建了该应用程序并在 Android Mobile 中运行它。

 02-25 20:18:42.181: A/DEBUG(583): pid: 23421, tid: 23439, name: main  >>> devnp.testing <<<
02-25 20:18:42.197: W/debuggerd(583): type=1400 audit(0.0:35378): avc: denied { search } for name="devnp.testing" dev="dm-1" ino=141182 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
02-25 20:18:42.260: A/DEBUG(583):     #11 pc 0009221b  /data/app/devnp.testing-1/lib/arm/libgpg.so
02-25 20:18:42.260: A/DEBUG(583):     #12 pc 00092e37  /data/app/devnp.testing-1/lib/arm/libgpg.so
02-25 20:18:42.261: A/DEBUG(583):     #13 pc 000933dd  /data/app/devnp.testing-1/lib/arm/libgpg.so
02-25 20:18:42.261: A/DEBUG(583):     #14 pc 0008dc69  /data/app/devnp.testing-1/lib/arm/libgpg.so (_ZNK3gpg28AndroidPlatformConfiguration5ValidEv+76)
02-25 20:18:42.261: A/DEBUG(583):     #15 pc 00053441  /data/app/devnp.testing-1/lib/arm/libgpg.so (_ZN3gpg12GameServices7Builder6CreateERKNS_28AndroidPlatformConfigurationE+40)
02-25 20:18:42.261: A/DEBUG(583):     #16 pc 000c73dd  /data/app/devnp.testing-1/lib/arm/libgpg.so (GameServices_Builder_Create+16)
02-25 20:18:43.054: W/ActivityManager(1439):   Force finishing activity devnp.testing/com.unity3d.player.UnityPlayerActivity
02-25 20:18:43.233: I/ActivityManager(1439): Process devnp.testing (pid 23421) has died
02-25 20:18:43.234: W/InputDispatcher(1439): channel 'd1b52d4 devnp.testing/com.unity3d.player.UnityPlayerActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
02-25 20:18:43.234: E/InputDispatcher(1439): channel 'd1b52d4 devnp.testing/com.unity3d.player.UnityPlayerActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
02-25 20:18:43.237: I/WindowState(1439): WIN DEATH: Window{d1b52d4 u0 devnp.testing/com.unity3d.player.UnityPlayerActivity}
02-25 20:18:43.237: W/InputDispatcher(1439): Attempted to unregister already unregistered input channel 'd1b52d4 devnp.testing/com.unity3d.player.UnityPlayerActivity (server)'

最佳答案

降级 .aar 文件可以解决问题

参见:https://github.com/playgameservices/play-games-plugin-for-unity/issues/1604

旧文件:https://drive.google.com/drive/u/0/folders/0B-w9u2zDKrHGUmtjMmk2VDhhSjA

以下是我解决此问题的方法:

  1. 转至 Assets > Play 服务解析器 > Android 解析器 > 设置 取消勾选“启用后台解析”(一旦我们降级 .aar 文件,这将抑制更新通知)

  2. 转到<android_sdk_path>\extras\google\m2repository\com\google\android\gms 。每个文件夹内都有版本文件夹(例如 10.0.1、10.2.0)。这些里面是我们需要的 .aar 文件,或者从上面的谷歌驱动器链接下载 我们需要以下文件:

    • 播放服务广告-10.0.1.aar
    • play-services-ads-lite-10.0.1.aar
    • 播放服务-auth-10.0.1.aar
    • play-services-auth-base-10.0.1.aar
    • play-services-base-10.0.1.aar
    • play-services-basement-10.0.1.aar
    • 播放服务-clearcut-10.0.1.aar
    • play-services-drive-10.0.1.aar
    • play-services-games-10.0.1.aar
    • 播放服务-gass-10.0.1.aar
    • 播放服务-nearby-10.0.1.aar
    • 播放服务任务-10.0.1.aar
  3. <unity_project_path>\Assets\Plugins\Android删除上面 .aar 文件的 10.2.0 版本及其 META 文件。

  4. 复制 10.0.1 版本
  5. 构建并运行您的项目。

关于android - Unity Google Play 服务插件 Social.localUser.Authenticate(...) 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42457572/

相关文章:

android - 如何更改工具栏名称并将图标与工具栏一起放置

c# - 在unity 2D c#中如何旋转像几何破折号这样的对象?

android - 自动生成适用于Android的google-services.json

android - 如何减少 web-RTC 库的大小?

java - 媒体播放器错误(-38,0)

c# - 如何调整 UI.Text alpha 以波浪图案点亮?

shader - 使用正交相机的屏幕空间环境遮挡?

ios - 适用于 iOS 的 Unity Google Play 服务 'TokenClient'

android - 错误 : Problems reading data from Binary store

java - 执行 doInBackground() 时发生错误,同时执行 facebook like