LoginSignup
5
2

More than 3 years have passed since last update.

1つのアプリでFirebaseプロジェクトを複数扱う方法

Last updated at Posted at 2021-03-11

はじめに

もし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

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2