无法通过 Kotlin Multiplatform 在 iOS 中使用 Guava 库

问题描述 投票:0回答:1

我正在尝试使用针对 Android 和 iOS 的 Kotlin Multiplatform。但是,当使用任务“iosSimulatorArm64”运行测试时,这些导入显示错误“未解决的引用”:

import com.google.common.graph.NetworkBuilder

我按照这个示例,build.gradle.kts 看起来像:

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
        }
    }

    sourceSets {
        commonTest {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation("com.google.guava:guava:33.0.0-jre")
                implementation("com.google.guava:guava:33.0.0-android")
            }
        }
        val androidUnitTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
    }
}

android {
    compileSdk = 34
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 21
    }
    namespace = "com.jetbrains.android"
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}
android build.gradle guava kotlin-multiplatform gradle-kotlin-dsl
1个回答
0
投票

guava 仅适用于 jvm/android。您无法从 iOS 使用它。您只能使用 jvm 兼容源集中的 guava。

© www.soinside.com 2019 - 2024. All rights reserved.