今天我在 Android Studio Hedgehog | 创建了一个空的 Kotlin 多平台应用程序 2023.1.1,我只在
build.gradle
文件夹的 shared
的插件部分添加了一行:
id("com.squareup.sqldelight") version "1.5.5"
按下 Sync 按钮后,出现错误
shared/build.gradle.kts:9:5: Unresolved reference: androidTarget
我确信这不是关于错误的初始文件结构,而是关于 sqldelight 插件行本身 - 错误的语法等等。 作为参考,我在这里留下了一些文件:
共享文件夹的build.gradle.kts
(仅第一行):
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
id("com.squareup.sqldelight") version "1.5.5"//this line was added only
}
kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
....
项目的build.gradle.kts
(所有线路):
plugins {
//trick: for the same plugin versions in all sub-modules
alias(libs.plugins.androidApplication).apply(false)
alias(libs.plugins.androidLibrary).apply(false)
alias(libs.plugins.kotlinAndroid).apply(false)
alias(libs.plugins.kotlinMultiplatform).apply(false)
}
libs.versions.toml
(所有线路)
[versions]
agp = "8.2.0"
kotlin = "1.9.20"
compose = "1.5.4"
compose-compiler = "1.5.4"
compose-material3 = "1.1.2"
androidx-activityCompose = "1.8.0"
[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" }
[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
我还尝试了该插件的另一种语法,在我添加的共享的
build.gradle
中
alias(libs.plugins.sqldelightPlugin)
并在
libs.versions.toml
中我添加了
[versions]
....
sqldelight = "1.5.5"
[plugins]
....
sqldelightPlugin = { id = "com.squareup.sqldelight", version.ref = "sqldelight" }
但无论如何我都遇到了同样的错误。
如何正确地将
com.squareup.sqldelight
插件添加到 Kotlin Multiplatform项目的共享
build.gradle
中?
尝试:
plugins {
id("app.cash.sqldelight") version "1.5.5"
}
文档。您正在使用 JAR 的组标识符,而不是 Gradle 插件 id1。
1一个单独的标识符,主要用于在 JAR 中定位插件类,但也可以在存储库中定位插件 JAR。