框架 'shared.framework' 缺少此目标所需的一个或多个架构:arm64。 Xcode 12.0 科特林 1.4.10

framework 'shared.framework' is missing one or more architectures required by this target: arm64. Xcode 12.0 kotlin 1.4.10

我使用 Kotlin Multiplatform 为 iOS 和 Android 创建了一个共享库,并且一切正常,直到我没有将 Xcode 更新为 12.0

当我将 Xcode 更新到 12.0 时,框架停止在真实设备上工作 (iphone) 但在模拟器上工作

我的Gradle

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("kotlin-android-extensions")
}
group = "com.example.multiplatform_android_ios"
version = "1.0-SNAPSHOT"

repositories {
    gradlePluginPortal()
    google()
    jcenter()
    mavenCentral()
}
kotlin {
    android()
    ios {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }
    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("com.google.android.material:material:1.2.0")
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.12")
            }
        }
        val iosMain by getting
        val iosTest by getting
    }
}
android {
    compileSdkVersion(29)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(29)
        versionCode = 1
        versionName = "1.0"
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
}
val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)

Xcode 12.0 Android Studio 4.1 RC 3 科特林 1.4.10

com.android.tools.build:gradle:4.1.0-rc03

我也遇到了同样的问题,按照以下步骤解决了:

  • 关闭Android工作室
  • 删除共享模块中的构建文件夹
  • 现在在 Xcode 中打开 iOS 应用程序并插入您的设备
  • 确保在 Xcode 项目
  • 的构建阶段中有 运行 这个脚本
cd "$SRCROOT/.."
./gradlew :shared:packForXCode -PXCODE_CONFIGURATION=${CONFIGURATION}
  • 现在建工程就可以成功了

根据 KT-41854,此问题应在 KMM 插件版本 0.1.3 中修复,可用于 Android Studio 4.1 和 4.2。请检查是否正确,如果仍有错误,请在问题跟踪器中发表评论。

我遇到了同样的问题。用 Xcode 打开 iosApp.xcodeproj。选择选项卡“构建设置”。选择子选项卡“全部”。转到“体系结构”部分。如果不存在,则创建项目“Excluded Architectures”。在调试“Any iOS Simulator SDK”下创建条目。作为值条目“i386”。如果您需要以相同的方式进行发布。现在,您可以尝试使用 Android Studio 进行无错误编译。对于非英特尔处理器,您需要将 arm64 添加到有价值的项目中。