0

I am trying out firebase auth UI ins simple Jetpack project. I followed the instructions here.

But signed in UI flow is not show, instead it shows me the main activity which is an empty constraint layout.

My code is as follows

MainActivity.kt

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.firebase.ui.auth.AuthUI
import com.google.firebase.auth.FirebaseAuth


class MainActivity : AppCompatActivity() {

    private lateinit var mFirebaseAuth: FirebaseAuth
    private  lateinit var mAuthStateListener: FirebaseAuth.AuthStateListener


    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Initialize Firebase Auth
        mFirebaseAuth = FirebaseAuth.getInstance()


        mAuthStateListener = FirebaseAuth.AuthStateListener { firebaseAuth -> // line 25


                val user = firebaseAuth.currentUser


                if (user != null){
                    Toast.makeText(applicationContext, "Already signed in", Toast.LENGTH_LONG).show()
                }
                else{
                    // Choose authentication providers
                    val providers = arrayListOf(
                        AuthUI.IdpConfig.EmailBuilder().build(),
                        AuthUI.IdpConfig.GoogleBuilder().build())

                    // Create and launch sign-in intent
                    startActivityForResult(
                        AuthUI.getInstance()
                            .createSignInIntentBuilder()
                            .setIsSmartLockEnabled(false)
                            .setAvailableProviders(providers)
                            .setTheme(R.style.AppTheme)      // Set theme
                            .setAvailableProviders(providers)
                            .setTosAndPrivacyPolicyUrls(
                                "https://example.com/terms.html",
                                "https://example.com/privacy.html")

                            .build(),
                        RC_SIGN_IN)
                }
        }
    }

    public override fun onStart() {
        super.onStart()
        mFirebaseAuth.addAuthStateListener { mAuthStateListener }
    }

    override fun onPause() {
        super.onPause()
        mFirebaseAuth.removeAuthStateListener { mAuthStateListener }
    }

    companion object {

        private const val RC_SIGN_IN = 123
    }

}

Dependencies

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

     // firebase
     implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
     implementation 'com.google.firebase:firebase-core:16.0.6'
     implementation 'com.google.firebase:firebase-auth:16.1.0'
     implementation 'com.google.android.gms:play-services-auth:16.0.1'


    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
}

For providers as you can see I am only using Email and Google signin. Those providers are enabled in the firebase console. I also have a fingerprint specified in the project(which was there by default).

I tried debugging by setting breakpoint at line 25, I saw that the AuthStateListener lambda was not executed. I do not know why.

Please help!


UPDATE :

According to pointers given by Peter in his answer, dependencies were updated as mentioned here, but the issue still exists.

user158
  • 12,852
  • 7
  • 62
  • 94

2 Answers2

0

Since you are using version FirebaseUI 4.1.0, then according to the docs:

As of version 4.1.0, FirebaseUI has the following dependency versions:

Library                 Version
firebase-auth           16.0.1
play-services-auth      15.0.1
firebase-database       16.0.1
firebase-firestore      17.0.1
firebase-storage        16.0.1

more info here:

https://github.com/firebase/FirebaseUI-Android/tree/version-4.1.0

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • I am getting `'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[15.0. 1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.` – user158 Feb 18 '19 at 09:06
  • are you using `implementation 'com.google.android.gms:play-services-auth:16.0.1'` in your code? – Peter Haddad Feb 18 '19 at 09:10
  • 15.0.1, I am reading https://stackoverflow.com/questions/54055141/in-project-app-a-resolved-google-play-services-library-dependency-depends-on-a let me try different versions. – user158 Feb 18 '19 at 09:12
  • still empty screen mate even though I updated the dependencies to latest auth UI according to https://github.com/firebase/FirebaseUI-Android/releases – user158 Feb 18 '19 at 09:27
  • are you still getting an error or not? Also I mean if you are not using google-play-services-auth in your code, no need to add it as a dependecy, are you sure it is not entering the `authlistener`? Please add a log before and after the `authlistener` – Peter Haddad Feb 18 '19 at 09:28
  • to answer your other question, since I am using google signin provider `play-services-auth` is necessary. – user158 Feb 18 '19 at 09:43
  • Please add a log before and after the authlistener and tell me what you get – Peter Haddad Feb 18 '19 at 09:48
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/188583/discussion-between-user158-and-peter-haddad). – user158 Feb 18 '19 at 09:53
0

Actually after posting an issue on github repo, I came to know that the sign in flow appear when there is an internet connection (in my case it was keeping Wifi turned ON).

So this issue allowed one of members of the repo to identify a flaw in Firebase Auth UI (Android), he created a pull request that allows end users to pick auth method when they are offline.

user158
  • 12,852
  • 7
  • 62
  • 94