Can't sign in with Firebase Auth on android

Viewed 426

I'm trying to authenticate with firebase. My initial error in android was [ Cleartext HTTP traffic to 10.0.2.2 not permitted ]. I read how, and enabled Cleartext. So now, I get responses from firebase. But it's always "a network error" stating the cause may be a timeout or unreachable host.

I've been reading what I could, and I'm not sure what to do next or what I over looked. Here are the steps I've made

  • Enabled Clear Text Traffic in manifest.xml
  • Created a network_security_config and specified it in my manfiest.xml
  • Updated firebase auth and google services dependendicies in gradle
  • Tried on a on real device (still fails)
  • Updated google play services on android emulator
  • Verified android emulator has internet access
  • Verified my Firebase project has my AppID and SHA-1
  • Verified Email authentication is enabled

Here's my call to firebase:

auth().createUserWithEmailAndPassword(data.email, data.password).addOnCompleteListener(
                    (task) -> {
                        hideProgressBar();
                        if (task.isSuccessful()) {
                           //do stuff on success...                   
                        } else {
                            String localizedMessage = task.getException().getLocalizedMessage();
                            errorText.setText(localizedMessage);
                        }
                    }

My Manifest.xml:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name=".MyApp">

My security config res/xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">10.0.2.2</domain>
    </domain-config>
</network-security-config>

I tried using the Firebase Emulator. Everything worked when emulating the auth instance

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // Unchanged code
        View v = inflater.inflate(getLayoutId(), container, false);
        initVM();
        progressBar = v.findViewById(R.id.progress_bar);
        errorText = v.findViewById(R.id.error_text);
        auth = FirebaseAuth.getInstance();

        //Added emulator code 
        auth.useEmulator("10.0.2.2", 9099);
        return v;
    }

The Stack Trace firebase has on failures

W/System: Ignoring header X-Firebase-Locale because its value was null.
W/LoginScreen: signInWithCredential:failure
    com.google.firebase.FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host) has occurred.
        at com.google.android.gms.internal.firebase-auth-api.zzto.zza(com.google.firebase:firebase-auth@@21.0.1:17)
        at com.google.android.gms.internal.firebase-auth-api.zzuw.zza(com.google.firebase:firebase-auth@@21.0.1:9)
        at com.google.android.gms.internal.firebase-auth-api.zzux.zzl(com.google.firebase:firebase-auth@@21.0.1:1)
        at com.google.android.gms.internal.firebase-auth-api.zzuu.zzk(com.google.firebase:firebase-auth@@21.0.1:25)
        at com.google.android.gms.internal.firebase-auth-api.zztl.zzh(com.google.firebase:firebase-auth@@21.0.1:1)
        at com.google.android.gms.internal.firebase-auth-api.zzpm.zza(com.google.firebase:firebase-auth@@21.0.1:2)
        at com.google.android.gms.internal.firebase-auth-api.zzvb.zza(com.google.firebase:firebase-auth@@21.0.1:28)
        at com.google.android.gms.internal.firebase-auth-api.zzul.zzq(com.google.firebase:firebase-auth@@21.0.1:4)
        at com.google.android.gms.internal.firebase-auth-api.zzpt.zzA(com.google.firebase:firebase-auth@@21.0.1:4)
        at com.google.android.gms.internal.firebase-auth-api.zztp.zzv(com.google.firebase:firebase-auth@@21.0.1:5)
        at com.google.android.gms.internal.firebase-auth-api.zzsb.zzd(com.google.firebase:firebase-auth@@21.0.1:3)
        at com.google.android.gms.internal.firebase-auth-api.zzsa.accept(Unknown Source:6)
        at com.google.android.gms.common.api.internal.zacj.doExecute(com.google.android.gms:play-services-base@@17.5.0:2)
        at com.google.android.gms.common.api.internal.zah.zaa(com.google.android.gms:play-services-base@@17.5.0:9)
        at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.zac(com.google.android.gms:play-services-base@@17.5.0:193)
        at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.zab(com.google.android.gms:play-services-base@@17.5.0:158)
        at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.zaa(com.google.android.gms:play-services-base@@17.5.0:126)
        at com.google.android.gms.common.api.internal.GoogleApiManager.handleMessage(com.google.android.gms:play-services-base@@17.5.0:164)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:223)
        at android.os.HandlerThread.run(HandlerThread.java:67)


0 Answers
Related