我正在尝试firebase auth UI-ins simple Jetpack项目我遵照指示
here
.
但是没有显示登录的UI流,而是显示了一个空约束布局的主活动。
我的代码如下
主要活动.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 {
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'
}
对于供应商,如你所见,我只使用电子邮件和谷歌登录这些提供程序在firebase控制台中启用。
我还有一个在项目中指定的指纹(默认情况下是在那里的)。
我试着在第25行设置断点进行调试,发现
AuthStateListener
兰姆达没有被处决我不知道为什么。
请帮忙!
更新:
根据Peter在他的答案中给出的指针,依赖项被更新为
here
但是这个问题仍然存在。