Unity / Firebase Google登录在Android上强制关闭

问题描述 投票:-1回答:2

因此,我尝试通过将其与Firebase混合使用来在Unity Apps上制作Google登录选项。因此,我导入了Google登录插件v1.04并编写了代码。将其构建为* .apk文件时,控制台上不会显示任何错误。但是,当我尝试登录时,在选择了我要用来登录的帐户后,它会强制关闭。这是我的完整代码:

using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Google;
using UnityEngine;
using Firebase.Auth;

public class googleAuth : MonoBehaviour
{
    [SerializeField] string webClientID = "190747548795-haa9ej8fkg584c1r5nkhu7u6ol50tmcf.apps.googleusercontent.com";
    GoogleSignInConfiguration configuration;
    private void Awake() {
        configuration = new GoogleSignInConfiguration{
        WebClientId = webClientID,
            RequestIdToken = true
        };
    }

    public void loginGoogle(){
      GoogleSignIn.Configuration = configuration;
      GoogleSignIn.Configuration.UseGameSignIn = false;
      GoogleSignIn.Configuration.RequestIdToken = true;
      GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnAuthenticationFinished);
    }
    void OnAuthenticationFinished(Task<GoogleSignInUser> task){
        if(task.IsCanceled)
            print("error");
        if(task.IsFaulted)
            print("error");
        if(task.IsCompleted){
            googleFirebase(task.Result.IdToken);
        }
    }
    void googleFirebase(string token){
        Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(token,null);
        FirebaseAuth.DefaultInstance.SignInWithCredentialAsync(credential);
    }
}
firebase unity3d google-signin
2个回答
1
投票

这意味着您缺少Plugins / Android /文件夹中的文件。

  1. 在Firebase控制台上创建APP。
  2. 身份验证->登录方法-> Google启用。
  3. 下载“ google-services.json”文件。
  4. 放入资产/文件夹,然后可以导入插件。
  5. 导入Jar解析器后,将解析所需的文件并在Plugins / Android中为Firebase创建文件夹。
  6. 然后,您需要在Build Settings中检查您的包ID并运行该应用程序。我认为您需要根据已正确创建应用的代码检查步骤5中的问题。

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.