sqldelight icon indicating copy to clipboard operation
sqldelight copied to clipboard

NullPointerException when adding SQLDelight 2.0.0 plugin to Compose Multiplatform project

Open krisbitney opened this issue 1 year ago • 10 comments

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")
        }
    }
}

krisbitney avatar Aug 16 '23 02:08 krisbitney

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

chrisjenx avatar Aug 16 '23 03:08 chrisjenx

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

anwarpro avatar Aug 23 '23 15:08 anwarpro

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.

krisbitney avatar Aug 23 '23 15:08 krisbitney

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

teewhydope avatar Sep 02 '23 16:09 teewhydope

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 avatar Sep 13 '23 09:09 krisbitney

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

krisbitney avatar Sep 13 '23 09:09 krisbitney

I am facing the same issue, any fix?

BassirouRabo avatar Sep 15 '23 07:09 BassirouRabo

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

BassirouRabo avatar Sep 15 '23 07:09 BassirouRabo

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

eye-dee avatar Mar 22 '24 13:03 eye-dee

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

ikotep avatar Apr 25 '24 17:04 ikotep