[英]Firebase login failed on mobile
I have a application in unity.我有一个统一的应用程序。 I can login to firebase in my pc and when I create an.exe but when I generate an apk the login failed.
我可以在我的电脑上登录 firebase,当我创建 an.exe 时,但是当我生成 apk 时,登录失败。 Should I configure anything else?
我应该配置其他东西吗?
My script我的脚本
void Start()
{
auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
}
public void Login()
{
string email = inputFieldEmail.text;
string password = inputFieldPassword.text;
auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
if (task.IsCanceled)
{
Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
GameManager.instance.SetNombre(email.Split('@')[0]);
signedIn = true;
});
}
Yes, you should configure on your Firebase console your mobile device keys.是的,您应该在您的 Firebase 控制台上配置您的移动设备密钥。 Also remember that Firebase is currently working with API 16+.
另请记住,Firebase 目前正在与 API 16+ 合作。
More information here: https://firebase.google.com/docs/unity/setup更多信息在这里: https://firebase.google.com/docs/unity/setup
Some brief advice on that code, try replacing ContinueWith
with ContinueWithOnMainThread
.关于该代码的一些简短建议,请尝试将
ContinueWith
替换为ContinueWithOnMainThread
。 This will make it easier to debug your code, and avoid any thread-related issues in Unity (in particular, your GameManager.instance.SetNombre
makes me nervous).这将使您更容易调试代码,并避免 Unity 中出现任何与线程相关的问题(尤其是您的
GameManager.instance.SetNombre
让我感到紧张)。 It's a drop in replacement.这是一个下降的替代品。
For authentication to work on Android, you need three things:要在 Android 上进行身份验证,您需要三样东西:
- Get config file for your Android app Go to your the Project settings in the Firebase console.
将 Android 应用程序 Go 的配置文件获取到 Firebase 控制台中的项目设置。
- In the Your apps card, select the package name of the app for which you need a config file.
在您的应用卡中,select 您需要配置文件的应用的名称 package。
- Click google-services.json.
单击 google-services.json。
- Move your config file into the module (app-level) directory of your app.
将配置文件移动到应用程序的模块(应用程序级)目录中。 Make sure that you only have this most recent downloaded config file in your app.
确保您的应用程序中只有这个最近下载的配置文件。
(note for step 4 in Unity - just put it somewhere in your Assets/ directory) (请注意 Unity 中的第 4 步 - 只需将其放在您的 Assets/ 目录中的某个位置)
Make sure that you've enabled analytics in your Firebase console.确保您已在 Firebase 控制台中启用分析。 It sounds like you've done this already.
听起来你已经这样做了。
Add your SHA-1 to Firebase. This is based on signing key, so each developer may need to register their local development SHA-1, and you'll want to register your final signing key.将您的 SHA-1 添加到 Firebase。这是基于签名密钥的,因此每个开发人员可能需要注册他们的本地开发 SHA-1,并且您需要注册您的最终签名密钥。 From the help site :
从帮助网站:
Follow these steps if you didn't initially provide a SHA certificate fingerprint for your Firebase Android app or if you need to add an additional one.
如果您最初没有为您的 Firebase Android 应用程序提供 SHA 证书指纹,或者如果您需要添加一个额外的指纹,请按照这些步骤操作。
- Make sure that you have the SHA fingerprint of your signing certificate.
确保您拥有签名证书的 SHA 指纹。
- In your Project settings, go to the Your apps card.
在您的项目设置中,go 到您的应用卡片。
- Select the Firebase Android app to which you want to add a SHA fingerprint.
Select Firebase Android 要添加 SHA 指纹的应用程序。
- Click Add fingerprint.
单击添加指纹。
- Enter or paste the SHA fingerprint, then click Save.
输入或粘贴 SHA 指纹,然后单击保存。
To get your development SHA-1 key , enter roughly this command:要获取您的开发 SHA-1 密钥,大致输入以下命令:
keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
And if you can't run the keytool command, I wrote this brief explainer .如果您不能运行 keytool 命令,我写了这个简短的解释器。 You can find it in your JDK directory (you have a JDK somewhere if you're making Android builds).
您可以在您的 JDK 目录中找到它(如果您正在构建 Android,则在某处有一个 JDK)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.