ios - 无法将 ios 应用程序构建到设备中,因为“嵌入式框架 'SharedCode.framework' 是为 iOS 模拟器构建的。”
问题描述
我使用 Kotlin Native(多平台)并且我创建了一个 TestKotinNative 应用程序,但只有在模拟器上运行时才能工作。当我在我的设备(iphone 7、13.4.1)上运行时,xcode 显示错误“TestKotlinNative.xcodeproj Building for iOS,但链接和嵌入式框架 'SharedCode.framework' 是为 iOS Simulator 构建的。” 我的 Xcode 版本:11.4.1 请帮帮我!感谢
这是我的 build.gradle.kts (与https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/06_SettingUpKotlinFramework相同)
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "SharedCode"
}
}
}
jvm("android")
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
}
}
val packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")
/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets
.getByName<KotlinNativeTarget>("ios")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from({ framework.outputDirectory })
into(targetDir)
/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText("#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$@\n")
gradlew.setExecutable(true)
}
}
tasks.getByName("build").dependsOn(packForXcode)
解决方案
在 Kotlin 多平台框架中继续使用新版本的 xCode 的一种肮脏方式是……在更改平台(模拟器和 iphone)以运行您的项目之前,只需进入框架位置并删除框架文件。XCode 将重新构建您的框架,应用程序将部署在您选择的平台上
推荐阅读
- java - 将反射方法作为参数传递(功能接口)
- java - 在 Maven 插件中提取注释
- reactjs - React Props:无法访问 GitHub API 对象(我不是那么精明)
- vue.js - 如何按需导入组件以减小文件大小 [Element-UI]
- c++ - C ++如何使用getline()检测eof
- javascript - 如何从 Javascript 中的本地 JSON 文件中获取数据
- java - 我们可以在子构造函数javaspring中更改父bean的自动装配吗?
- python - 将字符串函数应用于数据框
- confluence - 创建只能访问单个页面的用户
- angular - 仅在多个其他事件触发后,如何使用 RxJS 和 Observables 执行 http 请求?