cashapp / sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
https://cashapp.github.io/sqldelight/
Apache License 2.0
6.02k stars 503 forks source link

NullPointerException when adding SQLDelight 2.0.0 plugin to Compose Multiplatform project #4534

Open krisbitney opened 10 months ago

krisbitney commented 10 months ago

SQLDelight Version

2.0.0

Operating System

Mac OS

Gradle Version

8.1.1

Kotlin Version

1.9.0

Dialect

SQLite

AGP Version

8.1.0

Describe the Bug

When building, the MainViewController for iOS encounters a null pointer exception when attempting to construct an App instance.

I found that it's caused by adding or removing the SQLDelight plugin id("app.cash.sqldelight") version "2.0.0".

Even with no related dependencies, configuration, or code, the exception occurs when the plugin is present.

More details here: https://github.com/JetBrains/compose-multiplatform/issues/3437

Stacktrace

Available here: https://github.com/JetBrains/compose-multiplatform/issues/3437

Gradle Build Script

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("org.jetbrains.compose")
    id("app.cash.sqldelight") version "2.0.0"
}

kotlin {
    android()
    listOf(
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.compilations.getByName("main") {
            cinterops {
                val yuli_ios by creating {
                    val fwTarget = if (it.name == "iosArm64") "ios-arm64" else "ios-arm64_x86_64-simulator"
                    val fwDir = "src/nativeInterop/frameworks/yuli_ios.xcframework/$fwTarget/yuli_ios.framework"
                    defFile("src/nativeInterop/cinterop/yuli_ios.def")
                    includeDirs("$fwDir/Headers")
                    compilerOpts("-F$fwDir", "-framework", "yuli_ios")
                }
            }
        }
        it.binaries.framework {
            baseName = "shared"
            isStatic = true
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(compose.runtime)
                implementation(compose.foundation)
                implementation(compose.material3)
                @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
                implementation(compose.components.resources)
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
            }
        }
        val androidMain by getting {
            dependencies {
                api("androidx.activity:activity-compose:1.7.2")
                api("androidx.appcompat:appcompat:1.6.1")
                api("androidx.core:core-ktx:1.10.1")
                implementation("app.cash.sqldelight:android-driver:2.0.0")
                implementation("com.github.instagram4j:instagram4j:2.0.7")
            }
        }
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
            dependencies {
                implementation("app.cash.sqldelight:native-driver:2.0.0")
            }
        }
    }
}

android {
    compileSdk = (findProperty("android.compileSdk") as String).toInt()
    namespace = "io.github.krisbitney.yuli.common"

    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    sourceSets["main"].res.srcDirs("src/androidMain/res")
    sourceSets["main"].resources.srcDirs("src/commonMain/resources")

    defaultConfig {
        minSdk = (findProperty("android.minSdk") as String).toInt()
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlin {
        jvmToolchain(11)
    }
}

sqldelight {
    databases {
        create("SocialDatabase") {
            packageName.set("io.github.krisbitney.yuli.database")
        }
    }
}
chrisjenx commented 10 months ago

Might be related too: https://github.com/cashapp/sqldelight/issues/4533

anwarpro commented 10 months ago

Any update on this issue? I'm also facing this issue on iOS build.

krisbitney commented 10 months ago

No updates. I saw an issue on the JetBrains YouTrack that said the issue was in the Compose plugin, which I believe is closed source and maintained by Google.

teewhydope commented 10 months ago

No updates. I saw an issue on the JetBrains YouTrack that said the issue was in the Compose plugin, which I believe is closed source and maintained by Google.

the 2.1.0 snapshot works fine. check HERE for reference

krisbitney commented 9 months ago

No updates. I saw an issue on the JetBrains YouTrack that said the issue was in the Compose plugin, which I believe is closed source and maintained by Google.

the 2.1.0 snapshot works fine. check HERE for reference

Very cool. Thanks!

krisbitney commented 9 months ago

Unfortunately, I already migrated to Realm SDK (MongoDB). I'll have to give SQLDelight another shot in my next project.

BassirouRabo commented 9 months ago

I am facing the same issue, any fix?

BassirouRabo commented 9 months ago

No updates. I saw an issue on the JetBrains YouTrack that said the issue was in the Compose plugin, which I believe is closed source and maintained by Google.

the 2.1.0 snapshot works fine. check HERE for reference

I am using the SNAPSHOT version but still getting the same error

eye-dee commented 3 months ago

No updates. I saw an issue on the JetBrains YouTrack that said the issue was in the Compose plugin, which I believe is closed source and maintained by Google.

the 2.1.0 snapshot works fine. check HERE for reference

Doesn't work for me either I tried to run the project you attached as a reference and faced the same problem

ikotep commented 2 months ago

Hi, I am facing same issue, is there any update how to fix/avoid it?