https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Sai Charan

11/28/2023, 4:36 PM
I am trying to learn KMP, I am getting androidTarget {^ Unresolved reference: androidTarget error when trying to use sqldelight
p

Pablichjenkov

11/28/2023, 4:42 PM
Can you share the code of your SQLDelight integration
s

Sai Charan

11/28/2023, 4:44 PM
Copy code
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.compose.ExperimentalComposeLibrary

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsCompose)
    id("app.cash.sqldelight") version "2.0.0"


}

kotlin {
    @Suppress("OPT_IN_USAGE")
    targetHierarchy.default()
    androidTarget()
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
    
    jvm("desktop")
    
    sourceSets {
        val desktopMain by getting
        
        androidMain.dependencies {
            implementation(libs.compose.ui)
            implementation(libs.compose.ui.tooling.preview)
            implementation(libs.androidx.activity.compose)
        }
        desktopMain.dependencies {
            implementation(compose.desktop.currentOs)
        }
        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            @OptIn(ExperimentalComposeLibrary::class)
            implementation(compose.components.resources)
        }
    }
}

android {
    namespace = "org.example.project"
    compileSdk = libs.versions.android.compileSdk.get().toInt()

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

    defaultConfig {
        applicationId = "org.example.project"
        minSdk = libs.versions.android.minSdk.get().toInt()
        targetSdk = libs.versions.android.targetSdk.get().toInt()
        versionCode = 1
        versionName = "1.0"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    dependencies {
        debugImplementation(libs.compose.ui.tooling)
    }
}



compose.desktop {
    application {
        mainClass = "MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "org.example.project"
            packageVersion = "1.0.0"
        }
    }
}
sqldelight {
    databases {
        create("Database") {
            packageName.set("com.example.database")
        }
    }
}
j

Jeff Lockhart

11/28/2023, 4:52 PM
There have been a few threads recently with this problem: https://kotlinlang.slack.com/archives/C3PQML5NU/p1699456721120009?thread_ts=1699456721.120009&cid=C3PQML5NU The issue is you shouldn't declare the plugin version in your submodule project configuration. Instead, add the plugin with
apply false
to your top-level build.gradle.kts with the version declared there. Then just apply the plugin to your submodule without a version declaration.
🙌 1
p

Pablichjenkov

11/28/2023, 5:37 PM
I recall mentioned thread 🧵 you are right Jeff
s

Sai Charan

11/29/2023, 6:55 AM
Thanks it solved my problem
12 Views