Как интегрировать комплект учетной записи Huawei

В настоящее время я использую плагин Huawei от EvilMindDev.

Ниже представлен скрипт AccountManager.

using HuaweiMobileServices.Id;
using HuaweiMobileServices.Utils;
using System;
using UnityEngine;

namespace HmsPlugin
{
    public class AccountManager : MonoBehaviour
    {

    public static AccountManager GetInstance(string name = "AccountManager") => GameObject.Find(name).GetComponent<AccountManager>();

    private static HuaweiIdAuthService DefaultAuthService
    {
        get
        {
            Debug.Log("[HMS]: GET AUTH");
            var authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM).SetIdToken().CreateParams();
            Debug.Log("[HMS]: AUTHPARAMS AUTHSERVICE" + authParams);
            var result = HuaweiIdAuthManager.GetService(authParams);
            Debug.Log("[HMS]: RESULT AUTHSERVICE"+ result);
            return result;
        }
    }

    public AuthHuaweiId HuaweiId { get; private set; }
    public Action<AuthHuaweiId> OnSignInSuccess { get; set; }
    public Action<HMSException> OnSignInFailed { get; set; }

    private HuaweiIdAuthService authService;

    // Start is called before the first frame update
    void Awake()
    {
        Debug.Log("[HMS]: AWAKE AUTHSERVICE");
        authService = DefaultAuthService;
        Debug.Log("DefaultAuthService : "+DefaultAuthService);
        Debug.Log("authService : "+authService);
    }

    public void SignIn()
    {
        Debug.Log("[HMS]: Sign in " + authService);
        authService.StartSignIn((authId) =>
        {
            HuaweiId = authId;
            Debug.Log("HuaweiId : "+HuaweiId);
            OnSignInSuccess?.Invoke(authId);
        }, (error) =>
        {
            HuaweiId = null;
            OnSignInFailed?.Invoke(error);
        });
    }

    public void SignOut()
    {
        Debug.Log("authService.SignOut");
        authService.SignOut();
        HuaweiId = null;
    }
}
}

Ниже представлен скрипт AccountSignIn.

using HuaweiMobileServices.Id;
using HuaweiMobileServices.Utils;
using UnityEngine;
using UnityEngine.UI;
using HmsPlugin;
public class AccountSignIn : MonoBehaviour
{

private const string NOT_LOGGED_IN = "No user logged in";
private const string LOGGED_IN = "{0} is logged in";
private const string LOGIN_ERROR = "Error or cancelled login";

private Text loggedInUser;
private AccountManager accountManager;

// Start is called before the first frame update
void Start()
{
    loggedInUser = GameObject.Find("LoggedUserText").GetComponent<Text>();
    loggedInUser.text = NOT_LOGGED_IN;

    //accountManager = AccountManager.GetInstance();
    accountManager = GetComponent<AccountManager>();
    accountManager.OnSignInSuccess = OnLoginSuccess;
    accountManager.OnSignInFailed = OnLoginFailure;
    LogIn();
}

public void LogIn()
{
    accountManager.SignIn();
}

public void LogOut()
{
    accountManager.SignOut();
    loggedInUser.text = NOT_LOGGED_IN;
}

public void OnLoginSuccess(AuthHuaweiId authHuaweiId)
{
    loggedInUser.text = string.Format(LOGGED_IN, authHuaweiId.DisplayName);
}

public void OnLoginFailure(HMSException error)
{
    loggedInUser.text = LOGIN_ERROR;
}
}

Каждый раз, когда я пытаюсь войти в систему, я получаю эту ошибку. Это HuaweiIdAuthService.

Даже если я попробую предоставленную демонстрацию, у меня будет такая же ошибка. Если я попробую отладить с помощью Android Studio, он все равно выдаст мне ту же ошибку.

public void SignIn()
{
    Debug.Log("[HMS]: Sign in " + authService);
    authService.StartSignIn((authId) =>
    {
        HuaweiId = authId;
        Debug.Log("HuaweiId : "+HuaweiId);
        OnSignInSuccess?.Invoke(authId);
    }, (error) =>
    {
        HuaweiId = null;
        OnSignInFailed?.Invoke(error);
    });
}

authService ничего не возвращает. Откуда мне это взять?

2 ответа

Этот плагин имеет 2 ветки для Unity 2019 и Unity 2018.

  1. Вы должны активировать Account Kit API в галерее приложений Huawei.
  2. Проверить конфигурацию файла AndroidManifest
  3. Проверьте файл Agconnect-service.json

Это нулевой указатель. Пожалуйста, проверьте неназначенные объекты. Если вы ничего не можете найти, удалите проект и установите его снова, потому что иногда происходят подобные вещи.

Другие вопросы по тегам