android - Kotlin IOS/Android 跨平台实践教程 : Unresolved reference: platform

标签 android ios kotlin kotlin-multiplatform

我正在尝试学习如何使用 Kotlin 进行 IOS/Android 多平台开发。

在进行动手教程时,可在此处获取:https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/03_CreatingSharedCode

我在文件 SharedCode/src/iosMain/kotlin/actual.kt 中收到错误 Unresolved reference: platform:

package com.jetbrains.handson.mpp.mobile
import platform.UIKit.UIDevice

actual fun platformName(): String{
    return UIDevice.currentDevice.systemName() +
            " " +
            UIDevice.currentDevice.systemVersion
}

它只适用于 MacOS 还是我遗漏了什么?

感谢您的帮助。

最佳答案

看起来您的 Android Studio 和项目中的 Kotlin 运行时/编译器版本不匹配。确保将它们与最新且相同的版本对齐。例如,如果您的 IDE 中的 Kotlin 插件是 1.3.72,那么请确保您的项目 Gradle 中的 kotlin-gradle-plugin 也使用的是 1.3.72 版本。

关于android - Kotlin IOS/Android 跨平台实践教程 : Unresolved reference: platform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59337063/

相关文章:

android - 尽管使用了异步,为什么我仍然得到 NetworkOnMainThreadException?

android - 在 Android 中从 Facebook SDK 获取所有信息

android - 使用 Android NDK 编译 Boost 时 assert.h 冲突

android - 尝试在空对象引用上调用虚拟方法 'android.view.View android.view.View.getRootView()'

ios - 跟踪 GPUImage processImage 的进度(iOS)

ios - prepareForSegue 被调用两次,在演示过程中尝试呈现 <UINavigationController>

iphone - Xcode : Storyboarding with CoreData

android - 在 Android 中将文本设置为 "primary"

spring - 为什么 Spring Boot 2.7.x 不使用 kotlin 1.7 或 1.8

java - toBlockingFirst方法靠谱吗?