ttypic / swift-klib-plugin

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

Exception in thread "main" java.lang.IllegalStateException: -def or -pkg should be provided! #42

Open BoikoIlya opened 2 weeks ago

BoikoIlya commented 2 weeks ago

I have add plagin. kotlin version is 2.0.10

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

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

swiftklib{ create("image_converter"){ path = file("../iosApp/iosApp/image_converter_ios") packageName("com.kamancho.image_converter_ios") } }

@objc public class ImageConverterIos: NSObject { @objc public static func convertUIImageToByteArray(image: UIImage) -> NSData? { return image.pngData() as NSData? } }

and I get this:

Exception in thread "main" java.lang.IllegalStateException: -def or -pkg should be provided! Usage: cinterop options_list Options: -verbose [false] -> Enable verbose logging output -pkg -> place generated bindings to the package { String } -output, -o [nativelib] -> specifies the resulting library file { String } -libraryPath -> add a library search path { String } -staticLibrary -> embed static library to the result { String } -library, -l -> library to use for building { String } -libraryVersion, -lv [unspecified] -> resulting interop library version { String } -repo, -r -> repository to resolve dependencies { String } Warning: '-repo' ('-r') option is deprecated and will be removed in one of the future releases. Please use library paths instead of library names in all options such as '-library' ('-l'). -no-default-libs [false] -> don't link the libraries from dist/klib automatically -nodefaultlibs [false] -> don't link the libraries from dist/klib automatically Warning: Old form of flag. Please, use no-default-libs. -no-endorsed-libs [false] -> don't link the endorsed libraries from dist automatically -Xpurge-user-libs [false] -> don't link unused libraries even explicitly specified -nopack [false] -> Don't pack the produced library into a klib file -Xtemporary-files-dir -> save temporary files to the given directory { String } -Xproject-dir -> base directory for relative libraryPath { String } -Xkotlinc-option -> additional kotlinc compiler option { String } -Xoverride-konan-properties -> Override konan.properties.values { String } -Xkonan-data-dir -> Path to konan and dependencies root folder { String } -target [host] -> native target to compile to { String } -def -> the library definition file { String } -header -> header file to produce kotlin bindings for { String } -headerFilterAdditionalSearchPrefix, -hfasp -> header file to produce kotlin bindings for { String } -compilerOpts -> additional compiler options (allows to add several options separated by spaces) { String } Warning: -compilerOpts is deprecated. Please use -compiler-options. -compiler-options -> additional compiler options (allows to add several options separated by spaces) { String } -linkerOpts -> additional linker options (allows to add several options separated by spaces) { String } Warning: -linkerOpts is deprecated. Please use -linker-options. -linker-options -> additional linker options (allows to add several options separated by spaces) { String } -compiler-option -> additional compiler option { String } -linker-option -> additional linker option { String } -linker -> use specified linker { String } -Xcompile-source -> additional C/C++ sources to be compiled into resulting library { String } -Xsource-compiler-option -> compiler options for sources provided via -Xcompile-source { String } -Xshort-module-name -> A short name used to denote this library in the IDE { String } -Xmodule-name -> A full name of the library used for dependency resolution { String } -Xforeign-exception-mode -> Handle native exception in Kotlin: <terminate|objc-wrap> { String } -Xdump-bridges -> Dump generated bridges -Xdisable-exception-prettifier [false] -> Don't hide exceptions with user-friendly ones -Xuser-setup-hint -> A suggestion that is displayed to the user if produced lib fails to link { String } -Xdisable-experimental-annotation -> Don't add @ExperimentalForeignApi to generated Kotlin declarations -help, -h -> Usage info

at kotlinx.cli.ArgParser.printError(ArgParser.kt:348)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:263)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLibSafe(main.kt:247)
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:105)
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)
rubenalfon commented 1 week ago

I have the exact same issue, running kotlin 2.0.0, agp 8.3.2 and swiftklib 0.6.3.

rubenalfon commented 1 week ago

I think I fixed it...

My problem was that I was defining the path to the swift file for cinterops, but you need to define the path to the folder that contains it.

Also, I think these names should be the same:


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

swiftklib {
    create("NAME") {
        path = // path
        packageName(/* name */)
    }
}