ttypic / swift-klib-plugin

Gradle Plugin for injecting Swift code into Kotlin Multiplatform Mobile shared module
MIT License
200 stars 9 forks source link

fatal error: 'sys/cdefs.h' file not found #46

Closed stevdza-san closed 4 days ago

stevdza-san commented 5 days ago

This is my swift file:

import Foundation
import UIKit

@objc public class SMSHandler: NSObject {
    @objc public static func sendSms(number: String, message: String) {
        let sms = "sms:\(number)&body=\(message)"
        if let strURL = sms.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
           let url = URL(string: strURL) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        } else {
            print("Invalid SMS URL")
        }
    }
}

My kotlin code:

import com.stevdza_san.sms.SMSHandler

@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
actual class SMSManager {
    actual fun sendSMS(
        number: Int,
        message: String,
        onError: (String) -> Unit
    ) {
        SMSHandler.sendSmsWithNumber(
            number = number.toString(),
            message = message
        )
    }
}

And my gradle build file:

kotlin {
listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "ComposeApp"
            isStatic = true
        }

        iosTarget.compilations {
            val main by getting {
                cinterops {
                    create("sms")
                }
            }
        }
    }
}

swiftklib {
    create("sms") {
        path = file("../iosApp/iosApp/sms")
        packageName("com.stevdza_san.sms")
    }
}

``Exception in thread "main" java.lang.Error: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/usr/include/copyfile.h:35:10: fatal error: 'sys/cdefs.h' file not found /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h:75:10: fatal error: could not build module 'Darwin' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/usr/include/dispatch/dispatch.h:28:10: fatal error: could not build module 'Darwin' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/usr/include/os/object.h:28:10: fatal error: could not build module 'Darwin' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/usr/include/objc/objc-auto.h:36:10: fatal error: could not build module 'Darwin' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/usr/include/os/workgroup_base.h:15:10: fatal error: could not build module 'Darwin' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:10: fatal error: could not build module 'CoreFoundation' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/System/Library/Frameworks/Security.framework/Headers/SecBase.h:28:10: fatal error: could not build module 'CoreFoundation' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h:18:10: fatal error: could not build module 'CoreFoundation' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/usr/include/xpc/xpc.h:6:10: fatal error: could not build module 'os_object' at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:80) at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:15) at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:564) at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:308) at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLibSafe(main.kt:244) at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.access$processCLibSafe(main.kt:1) at org.jetbrains.kotlin.native.interop.gen.jvm.Interop.interop(main.kt:102) at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:49) at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:23) at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:44)

stevdza-san commented 5 days ago

Somehow kotlin 2.0.21 solved this issue.