Google Play服务在Unity Android上的登录无法正常工作

3
我正在尝试将 Google Play 服务添加到我的 Unity Android 项目中。我已经向项目实现了 Google Play 服务插件,并填写了所有凭据。我在开发者控制台上拥有两个不同的内部测试帐户。
这是我的问题:
- 帐户A:SignInStatus 成功,没有显示欢迎弹出消息。 - 帐户B:SignInStatus 取消并未登录。
这是因为内部测试还是其他原因?
Unity 版本:2019.4.16f1
gpgs 插件版本:0.11.01
以下是我的代码: 参考:https://github.com/playgameservices/play-games-plugin-for-unity
using GooglePlayGames;
private bool Authenticated;

public void Start() {
  PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
}

internal void ProcessAuthentication(SignInStatus status) {
  if (status == SignInStatus.Success) {
    // Continue with Play Games Services
    Authenticated = true;
  } else {
    // Disable your integration with Play Games Services or show a login button
    // to ask users to sign-in. Clicking it should call
    // PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
    Authenticated = false;
  }
}
1个回答

1

你的代码没有问题。

我刚创建了一个新项目,得到了一个新的 SHA-1,将我的账户添加到了新的 Google Play 控制台并验证了一切都测试成功。

在这样做的过程中,我们发现了以下问题: 如果您正在使用 11.01 版本,请按照以下步骤检查是否存在问题。

请按照以下步骤检查。 (Assets → External Dependency Manager → Android Resolver → Force Resolve)

Assets/GooglePlayGames/com.google.play.games/Editor/GooglePlayGamesPluginDependencies.xml:11: Repo path 'Packages/com.google.play.games/Editor/m2repository' does not exist.

如果出现以上错误,您可以通过选择以下两种解决方案之一来解决。

首先,请参考 @greg-hanes 的评论此处

具体方法是在 Assets/GooglePlayGames/com.google.play.games/Editor/m2repository 文件夹中创建一个 GooglePlayGamesPluginDependencies.xml 文件,并粘贴以下内容。

<?xml version="1.0" encoding="UTF-8" ?>
<dependencies>
    <!-- Internal library dependency generated at build time.
        It also defines the transitive dependencies on play-services
    -->
    <androidPackages>
        <androidPackage spec="com.google.games:gpgs-plugin-support:0.11.01">
            <repositories>
                <repository>Assets/GooglePlayGames/com.google.play.games/Editor/m2repository</repository>
            </repositories>
        </androidPackage>
    </androidPackages>
</dependencies>

然后再次强制解决。 (Gradle在此过程中未能获取依赖项。如果出现错误,请确保JDK路径设置正确。)

其次,将版本降级为10.14版本。

这是我编写的一段代码,只在运行时运行一次。当我运行它时,它成功地运行。

using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;

public static class Login
{
  [RuntimeInitializeOnLoadMethod]
  public static void SignIn()
  {
    PlayGamesPlatform.Instance.Authenticate(success =>
    {
      Debug.Log(success ? "Success Login" : "Failed Login");
    });
  }
}

您可以安装Android Logcat软件包来查看Android上的日志。

我不喜欢11.01版本,所以我使用10.14版本 :)

希望您的问题得到解决!


我尝试了您的代码,但在10.14版本中出现了错误。状态类型为布尔型,登录状态为枚举类型。回调函数:认证完成后要调用的回调函数。如果认证成功,则返回true;否则返回false。我该如何获取状态信息? - Salih Tunçel
我有一个不同的问题。对于已登录用户显示AdMob广告是否可信? - Salih Tunçel
@SalihTunçel ProcessAuthentication() 是一个回调方法,如果里面的条件为 Success,则成功,否则失败。您可以相应地分叉状态消息。(也许我没有很好地理解评论…?) - isakgo_
@SalihTunçel Google Play 游戏服务admob似乎没有太多关联。我们已经确认在同时运行 Google Play 游戏服务和 admob 时没有问题。 - isakgo_
1
@SalihTunçel 你是指在Authenticate()成功时的成功消息吗?你可以使用Debug.Log()自己指定它。 - isakgo_
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接