JetBrains / kotlin-native

Kotlin/Native infrastructure
Apache License 2.0
7.02k stars 566 forks source link

Build ios framework error Unresolved reference:platform #2743

Closed Adriannatsu closed 5 years ago

Adriannatsu commented 5 years ago

I'm following the tutorial in https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html and building a multiplatform Kotlin/Native using Android Studio. However, I met the problems of when I import platform.UIKit.UIDevice it appears to be unresolved reference.

Other than that, I can't get the output framework after compiling. This is my build.gradle of the SharedCode module:

apply plugin: 'kotlin-multiplatform'

kotlin {
targets {
    final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
                          ? presets.iosArm64 : presets.iosX64

    fromPreset(iOSTarget, 'iOS') {
        binaries {
            framework('SharedCode')
        }
    }

    fromPreset(presets.jvm, 'android')
}

sourceSets {
    commonMain.dependencies {
        api 'org.jetbrains.kotlin:kotlin-stdlib-common'
    }

    androidMain.dependencies {
        api 'org.jetbrains.kotlin:kotlin-stdlib'
    }
}
}

// workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations {
compileClasspath
}

 task packForXCode(type: Sync) {
final File frameworkDir = new File(buildDir, "xcode-frameworks")
final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
final def framework = kotlin.targets.iOS.binaries.getFramework("SharedCode", mode)

inputs.property "mode", mode
dependsOn framework.linkTask

from { framework.outputFile.parentFile }
into frameworkDir

doLast {
    new File(frameworkDir, 'gradlew').with {
        text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
        setExecutable(true)
    }
}
}
tasks.build.dependsOn packForXCode`

and when I run the task packForXcode,

Configure project :SharedCode Kotlin Multiplatform Projects are an experimental feature. Target 'iOS' for platform ios_x64 is ignored during build on this mingw_x64 machine. You can build it with a macos_x64 host.

Task :SharedCode:linkSharedCodeDebugFrameworkIOS SKIPPED Task :SharedCode:packForXCode NO-SOURCE

BUILD SUCCESSFUL in 2s 4:18:12 PM: Task execution finished 'packForXCode'.

I didn't get the output framework in my SharedCode/build folder.

olonho commented 5 years ago

Compiler clearly says that "Target 'iOS' for platform ios_x64 is ignored during build on this mingw_x64 machine. You can build it with a macos_x64 host." Building for Apple targets is supported on macOS hosts only.

anilthummar commented 4 years ago

When I will run below command in terminal that time getting this error in windows 10.

gradlew :sharedNative:build

Some Kotlin/Native targets cannot be built on this mingw_x64 machine and are disabled: In project ':sharedNative': target 'ios' (can be built with a macos_x64 host)

I am using windows10 OS for and create ios/android build

Please help me.

artdfel commented 4 years ago

Hello, @anilthummar! This is expected behavior, as iOS targets require a Mac host machine. You can find more details here.

anilthummar commented 4 years ago

Thank you @artdfel for the updates.