首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >KMM应用程序无法在模拟器中运行

KMM应用程序无法在模拟器中运行
EN

Stack Overflow用户
提问于 2021-07-08 18:39:20
回答 2查看 605关注 0票数 3

我是KMM的新手,我正在尝试将KMM项目作为一个pod集成到我的示例Xcode项目中。我可以将KMM Pod链接到我的Xcode项目。但是,如果我尝试调用其中一个函数,则会产生下面的错误。如果我不调用任何KMM函数,它就可以在我的模拟器中运行应用程序。

ViewController

代码语言:javascript
复制
import UIKit
import Multiplatform

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let a = Greeting()
        a.greeting()
    }
}
代码语言:javascript
复制
ld: warning: ignoring file /Users/avjiang/Developments/Multiplatform/SharedCode/build/cocoapods/framework/Multiplatform.framework/Multiplatform, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_MultiplatformGreeting", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

KMM应用程序只是一个简单的应用程序。在SharedCode -> commonMain -> kotlin -> Greeting中有一个Greeting类

下面是我对build.gradle.kts的配置

代码语言:javascript
复制
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

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

version = "1.0"

kotlin {
    android()

    cocoapods {
        // Configure fields required by CocoaPods.
        summary = "Some description for a Kotlin/Native module"
        homepage = "Link to a Kotlin/Native module homepage"
        frameworkName = "Multiplatform"
        ios.deploymentTarget = "13.5"
        podfile = project.file("/Users/avjiang/Developments/TestKotlinMultiplatformPod/Podfile")
    }

    val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iosTarget("ios") { }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
        val iosMain by getting
        val iosTest by getting
    }
}

android {
    compileSdkVersion(30)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(19)
        targetSdkVersion(30)
    }
}

这是我的项目build.gradle.kts

代码语言:javascript
复制
buildscript {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20")
        classpath("com.android.tools.build:gradle:4.2.2")
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}

基本上,我只是在遵循https://kotlinlang.org/docs/mobile/create-first-app.html的教程。还没有什么复杂的东西。我是不是漏掉了什么?

我的计算机配置:Mac mini M1 Xcode 13 beta 2 MacOS 11.4

谢谢

EN

回答 2

Stack Overflow用户

发布于 2021-07-08 20:28:00

错误:

代码语言:javascript
复制
ld: warning: ignoring file /Users/avjiang/Developments/Multiplatform/SharedCode/build/cocoapods/framework/Multiplatform.framework/Multiplatform, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64

您正在尝试为M1芯片模拟器Simulator-arm64构建,但是KMM还不支持它。你的KMM版本是为英特尔,Simulator-x86_64

对于M1 Mac,你需要在实际的iPhone设备上运行它,或者在Rosetta下运行Xcode (感谢评论中的菲利普)。

票数 6
EN

Stack Overflow用户

发布于 2021-11-10 12:39:11

您需要导入共享,因为KMM使用共享模块。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68300051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档