我试图实现FirebaseAuth UI到我的应用程序,但我已经遇到了一些问题。
我试图创建FirebaseUIActivity.kt的片段,但是当我拨打支持片段经理崩溃。
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, FirebaseUIActivity.newInstance()).commit()
下面是一些代码:
MainActivity.kt
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
// Support toolbar
setSupportActionBar(binding.toolbar)
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, FirebaseUIActivity.newInstance()).commit()
}
}
FirebaseUiActivity.kt
class FirebaseUIActivity : Fragment() {
// Choose authentication providers
companion object {
fun newInstance() = FirebaseUIActivity()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding: FirebaseUiFragmentBinding = DataBindingUtil.inflate(inflater, R.layout.firebase_ui_fragment, container, false)
return binding.root
}
override fun onResume() {
super.onResume()
}
private val providers = arrayListOf(
AuthUI.IdpConfig.EmailBuilder().build(),
AuthUI.IdpConfig.GoogleBuilder().build()
)
override fun startActivityForResult(intent: Intent?, requestCode: Int) {
super.startActivityForResult(intent, requestCode)
AuthUI.getInstance().createSignInIntentBuilder()
.setAvailableProviders(providers)
.build()
}
}
错误:
Caused by: java.lang.IllegalStateException: Check your google-services plugin configuration, the default_web_client_id string wasn't populated.
at com.firebase.ui.auth.util.Preconditions.checkConfigured(Preconditions.java:90)
at com.firebase.ui.auth.AuthUI$IdpConfig$GoogleBuilder.<init>(AuthUI.java:957)
at com.example.katzinbetihot.Firebase.FirebaseUIActivity.<init>(FirebaseUIActivity.kt:40)
at com.example.katzinbetihot.Firebase.FirebaseUIActivity$Companion.newInstance(FirebaseUIActivity.kt:21)
at com.example.katzinbetihot.main.MainActivity.onCreate(MainActivity.kt:24)
at android.app.Activity.performCreate(Activity.java:7149)
at android.app.Activity.performCreate(Activity.java:7140)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3031)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3191)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1920)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6912)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
感谢提前,埃梅克您的帮助!