cashapp / sqldelight

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

IOS App cannot build and run "compileKotlinIosArm64 Could not find" #4888

Closed Dardev12 closed 9 months ago

Dardev12 commented 9 months ago

SQLDelight Version

2.0.1

Operating System

MacOs

Gradle Version

8.2.0

Kotlin Version

1.9.21

Dialect

?

AGP Version

No response

Describe the Bug

In my KMM project this error appear in the 2.0.1 version when i try to launch my IOS app :

I have try the solution provide in this issue but it doesn't work for me : https://github.com/cashapp/sqldelight/issues/1619

The Log:

> Task :shared:compileKotlinIosArm64 FAILED

w: skipping /Users/darren/.gradle/caches/modules-2/files-2.1/app.cash.sqldelight/native-driver-iosarm64/2.0.1/195c8e06def48d9f09e2b6c745c29eead5a97cd8/native-driver.klib. Incompatible abi version. The current default is '1.7.0', found '1.8.0'. The library produced by 1.9.21 compiler

e: Could not find "/Users/darren/.gradle/caches/modules-2/files-2.1/app.cash.sqldelight/native-driver-iosarm64/2.0.1/195c8e06def48d9f09e2b6c745c29eead5a97cd8/native-driver.klib" in [/Users/darren/Documents/GitHub/LAND-APP-MOBILE/Land/iosLandApp/Pods, /Users/darren/.konan/klib, /Users/darren/.konan/kotlin-native-prebuilt-macos-aarch64-1.8.10/klib/common, /Users/darren/.konan/kotlin-native-prebuilt-macos-aarch64-1.8.10/klib/platform/ios_arm64]

Stacktrace

No response

Gradle Build Script

import com.dardev.buildsrc.FirebaseService
import com.dardev.buildsrc.Koin
import com.dardev.buildsrc.SQLDelight

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("com.google.gms.google-services")
    id("org.jlleitschuh.gradle.ktlint") version "11.5.1"
    id("app.cash.sqldelight") version "2.0.1"
    id("dev.icerock.mobile.multiplatform-resources")
}

kotlin {
    android()
    iosX64()
    iosArm64()
    iosSimulatorArm64()
    targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
        binaries.withType<org.jetbrains.kotlin.gradle.plugin.mpp.Framework> {
            linkerOpts.add("-lsqlite3")
        }
    }
    /*jvm {
        compilations.all {
            kotlinOptions {
                jvmTarget = "17" // ou "17"
            }
        }
    }*/
    jvmToolchain(17)

    cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        version = "1.0"
        ios.deploymentTarget = "14.1"
        podfile = project.file("../iosLandApp/Podfile")
        framework {
            baseName = "shared"
            export("dev.icerock.moko:resources:0.23.0")
            export("dev.icerock.moko:graphics:0.9.0")
            isStatic = true
        }
        extraSpecAttributes["resources"] = "['src/commonMain/resources/**', 'src/iosMain/resources/**']"
        extraSpecAttributes["exclude_files"] = "['src/commonMain/resources/MR/**']"
    }

    sourceSets {
        val ktorVersion = "2.3.3"
        val napierVersion = "2.6.1"

        val commonMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-cio:$ktorVersion")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
                implementation("io.github.aakira:napier:$napierVersion")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
                implementation("org.slf4j:slf4j-api:2.0.0")
                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
                api("dev.icerock.moko:resources:0.23.0")
                with(Koin) {
                    api(core)
                }
                with(FirebaseService) {
                    implementation(authentication)
                    implementation(firestore)
                }
                with(SQLDelight){
                    implementation(sqlCommonModule)
                }
            }
        }
        val commonTest by getting {
            dependencies {
                //implementation(kotlin("test"))
                //implementation("io.mockk:mockk:1.13.7")
                //implementation("io.mockk:mockk-common:1.9.3")
                /*with(Koin) {
                    api(test)
                }*/
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
                with(SQLDelight){
                    implementation(sqlAndroidModule)
                }
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
            dependencies {
                implementation("io.ktor:ktor-client-darwin:$ktorVersion")
                with(SQLDelight){
                    implementation(sqlIosModule)
                }
            }
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

/*sqldelight {
    database("landDatabase"){
        packageName = "com.dardev.land.database"
        sourceFolders = listOf("sqldelight")
    }
}*/

sqldelight {
    databases {
        create("LandDatabase") {
            packageName.set("com.dardev.land.database")
            srcDirs.setFrom("src/commonMain/sqldelight")
        }
    }
}

android {
    namespace = "com.dardev.land"
    compileSdk = 34

    defaultConfig {
        minSdk = 21
        targetSdkVersion(34)
    }
}

multiplatformResources {
    multiplatformResourcesPackage = "com.dardev.land" // required
    multiplatformResourcesClassName = "SharedRes"
    disableStaticFrameworkWarning = true
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
    verbose.set(true)
    ignoreFailures.set(false)
    disabledRules.set(setOf("final-newline", "no-wildcard-imports"))
    reporters {
        reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.PLAIN)
        reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE)
        reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.SARIF)
    }
}

dependencies {
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
    implementation("com.google.firebase:firebase-messaging:23.1.0")
}
chrisjenx commented 9 months ago

I have a similar issue, not the same "can not find" but downgrading to 2.0.0 fixes for me. Lemme post stack in a bit

kpgalligan commented 9 months ago

If somebody can produce a repro sample project (or have something open source), that'll help considerably. I am using this version without issue on some of our projects, so finding a repro might take a fair bit of time.

Dardev12 commented 9 months ago

I have a similar issue, not the same "can not find" but downgrading to 2.0.0 fixes for me. Lemme post stack in a bit

@chrisjenx I have try to downgrading to 2.0.0 but i got the same error : e: Could not find "/Users/darren/.gradle/caches/modules-2/files-2.1/app.cash.sqldelight/runtime-iosarm64/2.0.1/4bc07c023bb5d5d5111ed22c264fd77912fdd9b3/runtime.klib" in [/Users/darren/Documents/GitHub/LAND-APP-MOBILE/Land/iosLandApp/Pods, /Users/darren/.konan/klib, /Users/darren/.konan/kotlin-native-prebuilt-macos-aarch64-1.8.10/klib/common, /Users/darren/.konan/kotlin-native-prebuilt-macos-aarch64-1.8.10/klib/platform/ios_arm64]

kpgalligan commented 9 months ago

From the error:

...files-2.1/app.cash.sqldelight/runtime-iosarm64/2.0.1/...

That says 2.0.1, so either you didn't "downgrade", or a different dependency is pulling in 2.0.1.

Also note:

/Users/darren/.konan/kotlin-native-prebuilt-macos-aarch64-1.8.10/klib/platform/ios_arm64

kotlin-native-prebuilt-macos-aarch64-1.8.10 suggests you're using Kotlin 1.8.10, although it says above 1.9.21.

Again, if you can make an accessible project that reproduces your issue, it'll be much easier to comment on further.

Dardev12 commented 9 months ago
srcDirs.setFrom("src/commonMain/sqldelight")

Good i have create a repo for my setup with sqldelight the link : https://github.com/LAND-Projet/LandSqlDelight @kpgalligan

kpgalligan commented 9 months ago

@Dardev12 I tried your project and it seems to work fine. Added sqldelight to the version catalog, and added some code to hit the db from iOS. Otherwise, I didn't change anything with the config that would cause or fix the original issue you reported.

https://github.com/kpgalligan/LandSqlDelight

Screenshot 2023-12-07 at 11 04 44 AM

chrisjenx commented 9 months ago
> Task :shared:database:compileKotlinIosSimulatorArm64

> Task :application:shared:compileKotlinIosSimulatorArm64 FAILED
error: Could not find "co.touchlab:stately-common" in [/Users/chrisjenkins/git/kmm/application/iosApp/Pods, /Users/chrisjenkins/.konan/klib, /Users/chrisjenkins/.konan/kotlin-native-prebuilt-macos-aarch64-1.9.21/klib/common, /Users/chrisjenkins/.konan/kotlin-native-prebuilt-macos-aarch64-1.9.21/klib/platform/ios_simulator_arm64]
error: Compilation finished with errors

Might be related or not, can create a new ticket, looks like a pod isn't getting propagated correctly? Works if I downgrade.

chrisjenx commented 9 months ago

Oh mine was a simple fix:

iosMain {
            dependencies {
                implementation("co.touchlab:stately-common:2.0.6")
                implementation("app.cash.sqldelight:native-driver:$sqldelightVersion")
            }
        }

My SQLDelight Impl is in side a library kmm module, wondering if the transistive dependency isn't being pulled down. Hopefully someone else has an issue they will see this comment for fix

kpgalligan commented 9 months ago

@chrisjenx https://github.com/cashapp/sqldelight/issues/4357

It's likely something else is expecting the older Stately. Koin being the obvious one. Your change is the workaround needed.

Dardev12 commented 9 months ago

@Dardev12 I tried your project and it seems to work fine. Added sqldelight to the version catalog, and added some code to hit the db from iOS. Otherwise, I didn't change anything with the config that would cause or fix the original issue you reported.

https://github.com/kpgalligan/LandSqlDelight

Screenshot 2023-12-07 at 11 04 44 AM

Weird because for me when i run it and i get an error again.

Can you share me the version you use for gradle,kotlin and your kdoctor setup ?

kpgalligan commented 9 months ago

Gradle and Kotlin are in the repo:

Kdoctor output

Environment diagnose (to see all details, use -v option):
[✓] Operation System
[✓] Java
[✓] Android Studio
[✓] Xcode
[✓] CocoaPods

Conclusion:
  ✓ Your operation system is ready for Kotlin Multiplatform Mobile Development!
Dardev12 commented 9 months ago

Good Everything work for me now. My setup is clean ✅ Thank you for the support 😃 I will close this ticket