gradle Xcode中使用的KMM xcframework需要Rosetta:“为iOS Simulator-arm 64构建,但试图链接为iOS Simulator-x86_64构建的文件”

yqkkidmi  于 12个月前  发布在  iOS
关注(0)|答案(1)|浏览(143)

我通过以下方式从Android KMM项目中创建了一个xcframework:

#!/bin/bash

./gradlew :shared:packForXCodeArm -PXCODE_CONFIGURATION=Release
./gradlew :shared:packForXCodeX64 -PXCODE_CONFIGURATION=Release
FRAMEWORK_NAME="shared"
ARM64PATH="shared/build/xcode-framework-arm/${FRAMEWORK_NAME}.framework"
X64PATH="shared/build/xcode-framework-X64/${FRAMEWORK_NAME}.framework"
UNIVERSAL_PATH="shared/build/xcode-framework-universal/"

xcodebuild -create-xcframework -framework "${ARM64PATH}" -framework "${X64PATH}" -output "${UNIVERSAL_PATH}/${FRAMEWORK_NAME}.xcframework"

字符串
我的build.gradle.kts包含:

val packForXcodeArm by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val framework = kotlin.targets.getByName<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>("iosArm64").binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-framework-arm")
    from({ framework.outputDirectory })
    into(targetDir)
}

val packForXcodeX64 by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val framework = kotlin.targets.getByName<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>("iosX64").binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-framework-X64")
    from({ framework.outputDirectory })
    into(targetDir)
}


在我的M1上的Xcode中,当不使用Rosetta时,

ld: warning: ignoring file /Users/.../Library/Developer/Xcode/DerivedData/froeling_ios-dwqfcfqkcvofjtgtuipjhkedehfx/Build/Products/Debug-iphonesimulator/shared.framework/shared, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_SharedNetworkRequests", referenced from:
      objc-class-ref in LoginView.o


有没有一种方法可以在Xcode中创建一个没有Rosetta的xcframework?

fruv7luv

fruv7luv1#

该错误是正常的,因为您丢失了为iosSimulatorArm64构建的符号。
我没有使用KMM,但我检查过。从1.5.30版本开始,Kotlin支持4个新目标:

  1. macosArm64
  2. iosSimulatorArm64
  3. watchosSimulatorArm64
  4. tvosSimulatorArm64
    请在此处查看其发行说明:Kotlin1.5.30
    因此,为了摆脱这个错误,请针对iosSimulatorArm64进行构建,并将构建的结果与其他平台连接,以获得“真实的”通用xcframework。

相关问题