Open3

KMMでアプリを開発するためのあれこれ

NaNa

Firestore + SQLDelight をKMMに追加してiOSビルドを成功させる

インストール

Firestore

KMMプロジェクトに、サードパーティのライブラリの依存を追加する
https://github.com/GitLiveApp/firebase-kotlin-sdk

Xcode側でSPM経由でFirebase SDK をインストールする
とりあえずFirestore だけ入れる

SQLDelight

KMMのドキュメント通りに設定する
https://kotlinlang.org/docs/multiplatform-mobile-ktor-sqldelight.html#add-dependencies-to-the-multiplatform-library

いろいろやったら、gradle sync しておく

iOSでビルドエラー ld: framework not found FirebaseFirestore

ld: framework not found FirebaseFirestore

って言われたら、isStatic = true にしてStatic Library としてリンクさせる

kotlin {
    android()

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "AppShared"
            isStatic = true
        }
    }

    sourceSets {
        ...
    }

https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/288

Static / Dynamic の Pros Cons がわかりやすく書いてある
https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/288#issuecomment-1127101598

iOSでビルドエラー Undefined symbol: _sqlite3_bind_blob

Undefined symbol: _sqlite3_bind_blob
Undefined symbol: _sqlite3_bind_double
Undefined symbol: _sqlite3_bind_int64
Undefined symbol: _sqlite3_bind_null
Undefined symbol: _sqlite3_bind_parameter_index
Undefined symbol: _sqlite3_bind_text
Undefined symbol: _sqlite3_busy_timeout
Undefined symbol: _sqlite3_changes
Undefined symbol: _sqlite3_clear_bindings
Undefined symbol: _sqlite3_close
Undefined symbol: _sqlite3_close_v2
Undefined symbol: _sqlite3_column_blob
Undefined symbol: _sqlite3_column_bytes
Undefined symbol: _sqlite3_column_count
Undefined symbol: _sqlite3_column_double
Undefined symbol: _sqlite3_column_int64
Undefined symbol: _sqlite3_column_name
Undefined symbol: _sqlite3_column_text
Undefined symbol: _sqlite3_column_type
Undefined symbol: _sqlite3_db_config
Undefined symbol: _sqlite3_db_readonly
Undefined symbol: _sqlite3_errmsg
Undefined symbol: _sqlite3_finalize
Undefined symbol: _sqlite3_last_insert_rowid
Undefined symbol: _sqlite3_open_v2
Undefined symbol: _sqlite3_prepare16_v2
Undefined symbol: _sqlite3_reset
Undefined symbol: _sqlite3_step
Linker command failed with exit code 1 (use -v to see invocation)

って言われたら Xcode > Bulid Settings > Other Liker Flags-lsqlite3 を追加する

https://github.com/cashapp/sqldelight/issues/1442#issuecomment-523435492

NaNa

KMM の enum class を Swift Encodable に対応する スニペット🐶

enum class Season(
    val rawValue: String,
) {
    SPRING(rawValue = "spring"),
    SUMMER(rawValue = "summer"),
    AUTUMN(rawValue = "autumn"),
    WINTER(rawValue = "winter"),
}

import shared

extension Season: Encodable {

    public func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(self.rawValue)
    }
}