"Unresolved reference: NativeSqliteDriver" for sqldelight added to ios source set
Asked Answered
D

1

7

I am working on kotlin multiplatform project. I successfully added several libs to my build.gradle (ktor, coroutines, ...). I also added sqldelight to common, android and ios sourcesets. My ios dependency is defined like this:

 implementation "com.squareup.sqldelight:native-driver:1.4.0"

Gradle says that all is good. Code for android compiles:

actual fun createDb(): ToshlDatabase? {
val driver = AndroidSqliteDriver(ToshlDatabase.Schema, appContext, "toshl.db")
return ToshlDatabase(driver)

}

Code for ios does not, it does not find "NativeSqliteDriver":

actual fun createDb(): ToshlDatabase? {
val driver = NativeSqliteDriver(ToshlDatabase.Schema, "toshl.db");
return ToshlDatabase(driver)

}

I tried using older versions of com.squareup.sqldelight but it did not help. How to debug this thing?

EDIT: My shared build.gradle:

plugins {
id("org.jetbrains.kotlin.multiplatform")
id("com.android.library")
id ("org.jetbrains.kotlin.native.cocoapods")
id("kotlinx-serialization")
id("com.squareup.sqldelight")
 }

ext.coroutine_version = '1.3.5-native-mt'
ext.serializer_version = '0.20.0'
ext.ktor_version = '1.3.2'
ext.sqlDelight_version= '1.4.0'


android {
compileSdkVersion 29
buildToolsVersion '30.0.0'

defaultConfig {
    minSdkVersion 21
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    consumerProguardFiles 'consumer-rules.pro'
}

sourceSets {
    main {
        setRoot('src/androidMain')
    }
    release {
        setRoot('src/androidMainRelease')
    }
    debug {
        setRoot('src/androidMainDebug')
    }
    test {
        setRoot('src/androidUnitTest')
    }
    testRelease {
        setRoot('src/androidUnitTestRelease')
    }
    testDebug {
        setRoot('src/androidUnitTestDebug')
    }
}

  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
}

// CocoaPods requires the podspec to have a version.
version = "1.0"

kotlin {
//commonMain is implicitly declared
ios()
android()

cocoapods {
    // Configure fields required by CocoaPods.
    summary = "Some description for a Kotlin/Native module"
    homepage = "Link to a Kotlin/Native module homepage"

    // The name of the produced framework can be changed.
    // The name of the Gradle project is used here by default.
    frameworkName = "toshlShared"
}

sourceSets {
    commonMain.dependencies {
        api 'org.jetbrains.kotlin:kotlin-stdlib-common'

        // Ktor
        implementation("io.ktor:ktor-client-core:$ktor_version")
        implementation("io.ktor:ktor-client-json:$ktor_version")
        implementation("io.ktor:ktor-client-logging:$ktor_version")
        implementation("io.ktor:ktor-client-serialization:$ktor_version")
        implementation("io.ktor:ktor-serialization:$ktor_version")

        // COROUTINES
        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutine_version"

        // SERIALIZATION
        implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializer_version"

        // SQL Delight
        implementation("com.squareup.sqldelight:runtime:$sqlDelight_version")
        implementation("com.squareup.sqldelight:coroutines-extensions:$sqlDelight_version")

    }

    androidMain.dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
        implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"

        // Coroutines
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version")
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version")

        // Ktor
        implementation("io.ktor:ktor-client-android:$ktor_version")
        implementation("io.ktor:ktor-client-core-jvm:$ktor_version")
        implementation("io.ktor:ktor-client-json-jvm:$ktor_version")
        implementation("io.ktor:ktor-client-logging-jvm:$ktor_version")
        implementation("io.ktor:ktor-client-serialization-jvm:$ktor_version")

        // Serialize
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializer_version")

        // SQL Delight
        implementation("com.squareup.sqldelight:android-driver:$sqlDelight_version")
        implementation("com.squareup.sqldelight:coroutines-extensions-jvm:$sqlDelight_version")
    }

    iosMain.dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"

        // Coroutines
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutine_version")

        // Ktor
        implementation("io.ktor:ktor-client-ios:$ktor_version")
        implementation("io.ktor:ktor-client-core-native:$ktor_version")
        implementation("io.ktor:ktor-client-json-native:$ktor_version")
        implementation("io.ktor:ktor-client-logging-native:$ktor_version")
        implementation("io.ktor:ktor-client-serialization-native:$ktor_version")

        // Serialize
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serializer_version")

        // SQL Delight
        implementation "com.squareup.sqldelight:native-driver:$sqlDelight_version"
    }
}

}


 sqldelight {
ToshlDatabase { // This will be the name of the generated database class.
    packageName = "com.thirdframestudios.android.expensoor.db"
}
}

Kotlin version is 1.3.72

Disrespectful answered 15/7, 2020 at 13:39 Comment(7)
try uninstalling and re installing, after clean and rebuildExegete
Post more of your config. All of the kotlin section in build.gradle. Also, confirm your kotlin version.Benzophenone
Tried clean and rebuild and it did not help. @Kevin i edited my question.Disrespectful
Is gradle failing or is the IDE not finding it?Benzophenone
Gradle says "BUILD SUCCESSFUL" so i guess its IDE.Disrespectful
Gradle 6.5.1, AS 4.1 beta 3Disrespectful
@ManojPerumarath Do you not read the question? It is build time problem not a runtime problemPutsch
B
19

Intellij currently doesn't like the combined ios() target. Split them out:

val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }
Benzophenone answered 15/7, 2020 at 14:9 Comment(6)
Thanks. I checked all the other things many times, never thought about this.Disrespectful
This workaround helps. Is there an open bug on the Intellij YouTrack for this?Xylophagous
Not sure about open bugs.Benzophenone
This issue will hopefully be fixed in the near future, but I found this more-complete example here: github.com/cashapp/sqldelight/issues/…Puberulent
Not sure how that's more complex.Same fix (by the same person, me :)Benzophenone
I am having this same issue, I have tried the workaround above but it didn't work. Please does anyone have an uptown date solution.Aspire

© 2022 - 2024 — McMap. All rights reserved.