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

7
  • try uninstalling and re installing, after clean and rebuild Commented Jul 15, 2020 at 13:44
  • Post more of your config. All of the kotlin section in build.gradle. Also, confirm your kotlin version. Commented Jul 15, 2020 at 13:51
  • Tried clean and rebuild and it did not help. @Kevin i edited my question. Commented Jul 15, 2020 at 14:00
  • Is gradle failing or is the IDE not finding it? Commented Jul 15, 2020 at 14:05
  • Gradle says "BUILD SUCCESSFUL" so i guess its IDE. Commented Jul 15, 2020 at 14:07

1 Answer 1

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")
    }
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks. I checked all the other things many times, never thought about this.
This workaround helps. Is there an open bug on the Intellij YouTrack for this?
Not sure about open bugs.
This issue will hopefully be fixed in the near future, but I found this more-complete example here: github.com/cashapp/sqldelight/issues/…
Not sure how that's more complex.Same fix (by the same person, me :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.