Sqldelight: No com.squareup.sqldelight.drivers.native.NativeSqliteDriver on iOS

Created on 11 Oct 2020  路  4Comments  路  Source: cashapp/sqldelight

Build Environment
Android Studio: 4.1 RC
SQLDelight version: 1.4.4
OS: iOS 13,14
Gradle version:
Kotlin version: 1.4.10, KMM 0.1.3
AGP Version (if applicable):

Describe the bug
Using the latest plugins 1.4.3 for sql delight and Android 4.1 RC. still getting the compilation error with no com.squareup.sqldelight.drivers.native.NativeSqliteDriver

bug

Most helpful comment

Gradle version 4.1.0, I'm using the same gradle build following the tutorial at https://kotlinlang.org/docs/mobile/discover-kmm-project.html#ios-framework. After adding the lines you suggested the native driver was found and the code compiled. Thanks!

For completeness, here's the shared gradle.build.kts I have now:

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("kotlin-android-extensions")
    id("com.squareup.sqldelight")
}

group = "es.elhaso.lazers"
version = "1.0-SNAPSHOT"

repositories {
    gradlePluginPortal()
    google()
    jcenter()
    mavenCentral()
}

kotlin {
    android()
    ios {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }
    // Block from https://github.com/cashapp/sqldelight/issues/2044#issuecomment-721299517.
    val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation("com.squareup.sqldelight:runtime:${Versions.sqlDelight}")
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("com.google.android.material:material:1.2.0")
                implementation("com.squareup.okhttp3:okhttp:${Versions.okhttp}")
                implementation("com.squareup.sqldelight:android-driver:${Versions.sqlDelight}")
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.12")
            }
        }
        val iosMain by getting {
            dependencies {
                implementation("com.squareup.sqldelight:native-driver:${Versions.sqlDelight}")
            }
        }
        val iosTest by getting
    }
}

sqldelight {
    database("AppDatabase") {
        packageName = "es.elhaso.lazers.db"
    }
}

android {
    compileSdkVersion(29)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(29)
        versionCode = 1
        versionName = "1.0"
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
}
val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)

All 4 comments

Same thing with sqlDelight 1.4.4, Android Studio 4.1. Reached https://kotlinlang.org/docs/mobile/configure-sqldelight-for-data-storage.html#table-operations but can't progress further since the NativeSqliteDriver is for some reason not found on iOS (but it works for Android):

Captura de pantalla 2020-11-03 a las 17 34 55

Please post your ios source set config, as well as gradle version. If you use the combined ios() target config, you'll get this issue. We still use:

val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }

for our app dev. Will try to move to the hierarchical setting soon, but have had issues.

Example here: https://github.com/touchlab/KaMPKit/blob/master/shared/build.gradle.kts#L28

Gradle version 4.1.0, I'm using the same gradle build following the tutorial at https://kotlinlang.org/docs/mobile/discover-kmm-project.html#ios-framework. After adding the lines you suggested the native driver was found and the code compiled. Thanks!

For completeness, here's the shared gradle.build.kts I have now:

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("kotlin-android-extensions")
    id("com.squareup.sqldelight")
}

group = "es.elhaso.lazers"
version = "1.0-SNAPSHOT"

repositories {
    gradlePluginPortal()
    google()
    jcenter()
    mavenCentral()
}

kotlin {
    android()
    ios {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }
    // Block from https://github.com/cashapp/sqldelight/issues/2044#issuecomment-721299517.
    val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation("com.squareup.sqldelight:runtime:${Versions.sqlDelight}")
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("com.google.android.material:material:1.2.0")
                implementation("com.squareup.okhttp3:okhttp:${Versions.okhttp}")
                implementation("com.squareup.sqldelight:android-driver:${Versions.sqlDelight}")
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.12")
            }
        }
        val iosMain by getting {
            dependencies {
                implementation("com.squareup.sqldelight:native-driver:${Versions.sqlDelight}")
            }
        }
        val iosTest by getting
    }
}

sqldelight {
    database("AppDatabase") {
        packageName = "es.elhaso.lazers.db"
    }
}

android {
    compileSdkVersion(29)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(29)
        versionCode = 1
        versionName = "1.0"
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
}
val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)

The configuration in the kmm-networking-and-data-storage final works for me @chokokatana @sreexamus

...

    val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iOSTarget("ios") {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }

....

val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidbilik picture davidbilik  路  3Comments

kuhnroyal picture kuhnroyal  路  4Comments

Nishant-Pathak picture Nishant-Pathak  路  3Comments

treelzebub picture treelzebub  路  3Comments

LouisCAD picture LouisCAD  路  5Comments