gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:32:10 29 4
gpt4 key购买 nike

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

ViewController

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()
}
}
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 里面有一个 Greeting 类 -> commonMain -> kotlin -> Greeting

下面是我对 build.gradle.kts

的配置
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

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 M1Xcode 13 beta 2MacOS 11.4

谢谢

最佳答案

错误:

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 版本适用于 Intel,Simulator-x86_64

对于 M1 Mac,您需要在您的实际 iPhone 设备上运行它或在 Rosetta 下运行 Xcode(感谢 Philip 在评论中的说明)。

关于ios - KMM 应用程序无法在模拟器中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68300051/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com