0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

KotlinMultiplatformでFirebaseを使う

Posted at

前回からの続きです。
今回は、Firebaseを導入していきます。

Android、iOS共に通常のセットアップはそのまま行います。
google-services.jsonの設定やGoogleService-Info.plistは通常通りです。
ライブラリーの導入も通常通り行います。

Android
composeAppのモジュールに追加します。今回はauthにしています。
使用したい機能を導入してください。

.gradle
implementation(dependencies.platform("com.google.firebase:firebase-bom:xx.x.x"))
implementation(libs.google.firebase.auth.ktx)

iOS
SPMにて導入します。

こちらを参考にしてみてください

FirebaseApp.configure()
初期化も忘れずに行ってください

これで完成ではなく、共通で使用したいロジック部分なので、sharedcommonMainにも必要になります。

sharedのモジュール

.gradle
androidMain.dependencies {
    implementation("dev.gitlive:firebase-auth:2.3.0")
}

GitLiveを導入すると
commonMainからFirebase.authを呼び出せるようになります。
(GitLive は公式の Firebase SDK をラップしているため、Android/iOS の通常セットアップを済ませれば共通コードから利用できます)

必要な処理をcommonMainに記載すれば両OSで使用できます。

import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.auth.auth

以上になります。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?