Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 244
DixieFlatline Avatar asked Jul 15 '20 13:07

DixieFlatline


1 Answers

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")
    }
like image 180
Kevin Galligan Avatar answered Nov 13 '22 07:11

Kevin Galligan