将 sqldelight 的“未解决的参考:NativeSqliteDriver”添加到 ios 源集
Posted
技术标签:
【中文标题】将 sqldelight 的“未解决的参考:NativeSqliteDriver”添加到 ios 源集【英文标题】:"Unresolved reference: NativeSqliteDriver" for sqldelight added to ios source set 【发布时间】:2020-11-05 00:44:39 【问题描述】:我正在从事 kotlin 多平台项目。我成功地将几个库添加到我的 build.gradle(ktor、协程......)。我还将 sqldelight 添加到 common、android 和 ios 源集。 我的 ios 依赖是这样定义的:
implementation "com.squareup.sqldelight:native-driver:1.4.0"
Gradle 说一切都很好。 android编译代码:
actual fun createDb(): ToshlDatabase?
val driver = AndroidSqliteDriver(ToshlDatabase.Schema, appContext, "toshl.db")
return ToshlDatabase(driver)
ios 的代码没有,它没有找到“NativeSqliteDriver”:
actual fun createDb(): ToshlDatabase?
val driver = NativeSqliteDriver(ToshlDatabase.Schema, "toshl.db");
return ToshlDatabase(driver)
我尝试使用旧版本的 com.squareup.sqldelight,但没有帮助。 这个东西怎么调试?
编辑:我的共享 build.gradle:
plugins
id("org.jetbrains.kotlin.multiplatform")
id("com.android.library")
id ("org.jetbrains.kotlin.native.cocoapods")
id("kotlinx-serialization")
id("com.squareup.sqldelight")
ext.coroutine_version = '1.3.5-native-mt'
ext.serializer_version = '0.20.0'
ext.ktor_version = '1.3.2'
ext.sqlDelight_version= '1.4.0'
android
compileSdkVersion 29
buildToolsVersion '30.0.0'
defaultConfig
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
sourceSets
main
setRoot('src/androidMain')
release
setRoot('src/androidMainRelease')
debug
setRoot('src/androidMainDebug')
test
setRoot('src/androidUnitTest')
testRelease
setRoot('src/androidUnitTestRelease')
testDebug
setRoot('src/androidUnitTestDebug')
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// CocoaPods requires the podspec to have a version.
version = "1.0"
kotlin
//commonMain is implicitly declared
ios()
android()
cocoapods
// Configure fields required by CocoaPods.
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
// The name of the produced framework can be changed.
// The name of the Gradle project is used here by default.
frameworkName = "toshlShared"
sourceSets
commonMain.dependencies
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
// Ktor
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-json:$ktor_version")
implementation("io.ktor:ktor-client-logging:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
implementation("io.ktor:ktor-serialization:$ktor_version")
// COROUTINES
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutine_version"
// SERIALIZATION
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializer_version"
// SQL Delight
implementation("com.squareup.sqldelight:runtime:$sqlDelight_version")
implementation("com.squareup.sqldelight:coroutines-extensions:$sqlDelight_version")
androidMain.dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version")
// Ktor
implementation("io.ktor:ktor-client-android:$ktor_version")
implementation("io.ktor:ktor-client-core-jvm:$ktor_version")
implementation("io.ktor:ktor-client-json-jvm:$ktor_version")
implementation("io.ktor:ktor-client-logging-jvm:$ktor_version")
implementation("io.ktor:ktor-client-serialization-jvm:$ktor_version")
// Serialize
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializer_version")
// SQL Delight
implementation("com.squareup.sqldelight:android-driver:$sqlDelight_version")
implementation("com.squareup.sqldelight:coroutines-extensions-jvm:$sqlDelight_version")
iosMain.dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutine_version")
// Ktor
implementation("io.ktor:ktor-client-ios:$ktor_version")
implementation("io.ktor:ktor-client-core-native:$ktor_version")
implementation("io.ktor:ktor-client-json-native:$ktor_version")
implementation("io.ktor:ktor-client-logging-native:$ktor_version")
implementation("io.ktor:ktor-client-serialization-native:$ktor_version")
// Serialize
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serializer_version")
// SQL Delight
implementation "com.squareup.sqldelight:native-driver:$sqlDelight_version"
sqldelight
ToshlDatabase // This will be the name of the generated database class.
packageName = "com.thirdframestudios.android.expensoor.db"
Kotlin 版本是 1.3.72
【问题讨论】:
在清理和重建后尝试卸载并重新安装 发布更多您的配置。 build.gradle 中的所有 kotlin 部分。另外,请确认您的 kotlin 版本。 尝试清理和重建,但没有帮助。 @Kevin 我编辑了我的问题。 是 gradle 失败还是 IDE 没有找到它? Gradle 说“构建成功”所以我猜它的 IDE。 【参考方案1】:Intellij 目前不喜欢组合的 ios()
目标。把它们分开:
val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
if (onPhone)
iosArm64("ios")
else
iosX64("ios")
【讨论】:
谢谢。其他的东西我检查了很多次,从来没有想过这个。 此变通方法有帮助。 Intellij YouTrack 上是否存在针对此问题的开放错误? 不确定打开的错误。 这个问题有望在不久的将来得到解决,但我在这里找到了这个更完整的示例:github.com/cashapp/sqldelight/issues/… 不确定这有多复杂。相同的修复(由同一个人,我 :)以上是关于将 sqldelight 的“未解决的参考:NativeSqliteDriver”添加到 ios 源集的主要内容,如果未能解决你的问题,请参考以下文章