I'm trying to implement FirebaseAuth UI to my app, but I've ran into some issues.
I'm trying to create the FirebaseUIActivity.kt as a fragment, but when I call the support fragment manager it crashes.
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, FirebaseUIActivity.newInstance()).commit()
Here is some code:
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()
}
}
Error:
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)
Thanks for your help in advance, Emek!