question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot generate database class in KMM project

See original GitHub issue

Build Environment SQLDelight version: 1.4.4 IDE version: Android Studio 4.1 Dialect: SQLLITE

Describe the bug I cannot get my database class to be generated in a fresh project created with KMM android/ios

In shared/build.gradle.kts

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("kotlin-android-extensions")
    id("com.squareup.sqldelight")
}
...
sqldelight {
    database("TestDatabase") {
        packageName = "com.jeantuffier.testkmm.sqldelight"
    }
}

In build.gradle.kts

buildscript {
    repositories {
        gradlePluginPortal()
        jcenter()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
        classpath("com.android.tools.build:gradle:4.1.0")
        classpath ("com.squareup.sqldelight:gradle-plugin:1.4.4")
    }
}
group = "com.jeantuffier.testkmm"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

In settings.gradle.kts

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        jcenter()
        mavenCentral()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
                useModule("com.android.tools.build:gradle:4.0.1")
            }
        }
    }
}
rootProject.name = "TestKMM"


include(":androidApp")
include(":shared")

I followed the documentation available here : https://cashapp.github.io/sqldelight/multiplatform_sqlite/ I cannot import/use the class TestDatabase, so I guess it’s not generated. I also tried to create the driver factories, it works for android but in iosMain, I cannot access NativeSqliteDriver

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
AlecStrongcommented, Apr 15, 2021

Clarified the documentation on master

0reactions
jeantuffiercommented, Oct 19, 2020

The documentation also says this :

// An array of folders where the plugin will read your ‘.sq’ and ‘.sqm’ // files. The folders are relative to the existing source set so if you // specify [“db”], the plugin will look into ‘src/main/db’. // Defaults to [“sqldelight”] (src/main/sqldelight) sourceFolders = [“db”]

It seems like the default is actually commonMain, but it would be nice to be able to define this value as “non relative”. In my use case, I want to share the database logic between ios and android, but my kmp project also targets backend so I created another target clientCommon for some of the logic that ios and android target depend on. it would be nice to be able too simply write sourceFolders = ["src/clientCommon"]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sqldelight database schema not generated - Stack Overflow
I have a KMM project and want to use SqlDelight library, but when I build the project database schema not generated and table...
Read more >
The "Database" class doesn't exist in sqldelight : r/Kotlin - Reddit
You have to build the project first so it can generate the Database class for you. After building it, it should compile as...
Read more >
KMM can not preview SwiftUI : KTIJ-22229 - YouTrack
The Problem I'm having is that I can not preview the swift ui views. When clicking on resume in the preview an error...
Read more >
KMM QuickStart Guide. Getting started with Kotlin…
In Android Studio, select File -> New -> New project. “Create new project” wizard will open. Select KMM Application and click Next.
Read more >
What's new in Kotlin 1.7.20
Check out the performance boost on your JVM projects and compare it with ... This makes data object declarations perfect for sealed class...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found