はじめに
もし1つのアプリに複数のFirebaseプロジェクトを使いたい場合のご紹介です。
ちなみに今回はAuthで確認しましたが、CloudFirestoreなど他のサービスでも使えると思います。
コードの書き方
AuthFragment.kt
// 二つ目以降のgoogle-services.jsonのid,keyを入力します
//setProjectId -> project_id
//setApplicationId -> mobilesdk_app_id
//setApiKey -> current_key
val options = FirebaseOptions.Builder()
.setProjectId("xxxxxxxxxx")
.setApplicationId("xxxxxxx")
.setApiKey("xxxxxxxxxx")
.build()
Firebase.initialize(context /* Context */, options, "secondary")
val secondary = Firebase.app("secondary")
authSecondary = Firebase.auth(secondary)
// authSecondaryを使って実装すればOkです
authSecondary.signInWithEmailAndPassword()
.addOnCompleteListener {
// ログイン処理を書く
}
二つ目以降のgoogle-services.jsonをディレクトリーはこんなかんじでもいけるみたいです
/app/project-demo/google-services.json
参考URL