简体   繁体   中英

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. 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. Also remember that Firebase is currently working with API 16+.

More information here: https://firebase.google.com/docs/unity/setup

Some brief advice on that code, try replacing ContinueWith with 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). It's a drop in replacement.

For authentication to work on Android, you need three things:

  1. a google-services.json file (there's a chance that you have a GoogleService-Info.plist if you registered an iOS app). From the help site :
  1. Get config file for your Android app Go to your the Project settings in the Firebase console.
  2. In the Your apps card, select the package name of the app for which you need a config file.
  3. Click google-services.json.
  4. 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)

  1. Make sure that you've enabled analytics in your Firebase console. It sounds like you've done this already.

  2. 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. 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.

  1. Make sure that you have the SHA fingerprint of your signing certificate.
  2. In your Project settings, go to the Your apps card.
  3. Select the Firebase Android app to which you want to add a SHA fingerprint.
  4. Click Add fingerprint.
  5. Enter or paste the SHA fingerprint, then click Save.

To get your development SHA-1 key , enter roughly this command:

keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore

And if you can't run the keytool command, I wrote this brief explainer . You can find it in your JDK directory (you have a JDK somewhere if you're making Android builds).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM