Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Can not build ios app into device because "embedded framework 'SharedCode.framework' was built for iOS Simulator." #4182

Closed
lehanphong opened this issue May 21, 2020 · 3 comments
Assignees

Comments

@lehanphong
Copy link

lehanphong commented May 21, 2020

I have create a TestKotinNative app, but only work when run on simulator.
When I run on my device (iphone 7, 13.4.1), xcode show error "TestKotlinNative.xcodeproj Building for iOS, but the linked and embedded framework 'SharedCode.framework' was built for iOS Simulator."
My Xcode version: 11.4.1
Please help me! Thank
Screen Shot 2020-05-21 at 15 21 20

@artdfel
Copy link
Contributor

artdfel commented May 21, 2020

Hello, @lehanphong!
First of all, I got to remind you that Kotlin/Native issue tracker is in the process of migration onto the YouTrack(#4079).
So, if you want to report a bug or propose a feature - please use this link - https://kotl.in/issue. For usage-related questions - please ask on StackOverflow with kotlin-native tag: https://stackoverflow.com/questions/ask?tags=kotlin-native. For community discussions - use #kotlin-native and #multiplatform channels in Slack workspace for Kotlin community -- https://slack.kotl.in.
About this particular question - this one seems like an incorrect build configuration, rather than a bug. Please share your Gradle script contents so anything more specific can be said. Check if there is an iosArm32 or iosArm64 target in it - those are for targeting a device. If there is only iosX64, this behavior can be assumed as expectable.

@lehanphong
Copy link
Author

lehanphong commented May 22, 2020

yes, I created a new issue on youtrack, https://youtrack.jetbrains.com/issue/KT-39118

@artdfel This is my build.gradle.kts (same with https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/06_SettingUpKotlinFramework)

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)

@artdfel
Copy link
Contributor

artdfel commented May 22, 2020

Okay then, I'm closing this one as a duplicate. I also found you posted the question to the StackOverflow and answered there, please check if my advice helps.

@artdfel artdfel closed this as completed May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants