7

我正在从事 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

4

1 回答 1

18

Intellij 目前不喜欢组合ios()目标。把它们分开:

val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }
于 2020-07-15T14:09:31.773 回答