Closed
Description
First I asked a question on SO but there was no solution. This may be a bug or my mistake.
Step 2: Describe your environment
- Android device: LG Zero
- Android OS version: 6.0
- Google Play Services version: play-services-auth : 16.0.1
- Firebase/Play Services SDK version: , firebase-core:16.0.6
- FirebaseUI version: 4.3.1
Step 3: Describe the problem:
When running the app firebase auth ui sign in flow is not show, instead shows the main activity, which in this case a blank constraint layout.
Steps to reproduce:
- Clone the repository at https://github.com/nerdyadventurer/firebase-auth-ui
- open project using android studio and setup firebase authentication(enable Google and Email authentication providers from the firebase console)
- Run the app
Observed Results:
- What happened? This could be a description,
logcat
output, etc.
Logcat is empty.
Shows the main activity (which is black in this case)
Expected Results:
- What did you expect to happen?
Showing the sign in flow with Google sign in, email sign in buttons and etc.
Relevant Code:
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'
// testing
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
}
MainActivity.kt
package example.com.firebaseauthui
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.firebase.ui.auth.AuthUI
import com.firebase.ui.auth.IdpResponse
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 ->
val user = mFirebaseAuth.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)
//.setLogo(R.drawable.my_great_logo) // Set logo drawable
.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 onResume() {
// super.onResume()
// mFirebaseAuth.addAuthStateListener { mAuthStateListener }
//
// }
override fun onPause() {
super.onPause()
mFirebaseAuth.removeAuthStateListener ( mAuthStateListener )
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN) {
val response = IdpResponse.fromResultIntent(data)
if (resultCode == Activity.RESULT_OK) {
// Successfully signed in
val user = FirebaseAuth.getInstance().currentUser
// ...
} else {
// Sign in failed. If response is null the user canceled the
// sign-in flow using the back button. Otherwise check
// response.getError().getErrorCode() and handle the error.
// ...
}
}
}
private fun signOut() {
AuthUI.getInstance()
.signOut(this)
.addOnCompleteListener {
// ...
}
}
companion object {
private const val RC_SIGN_IN = 123
}
}
Please help