Error importing a framework from Swift to Kotlin in Kotlin Multiplatform

Viewed 102

I have exported a framework that consists of two classes in Swift, I have used the @objc annotation. I am trying to import it to Kotlin now and I have created a .def file with the following structure:

language = Objective-C
package = platform.iOSWrapper
modules = SingletonFramework

and in my build.gradle I've put these two:

iosX64() {
                compilations.getByName("main") {
                    val DateTools by cinterops.creating {
                        // Path to .def file
                        defFile("src/iosMain/iOSWrapperFramework.def")

                        compilerOpts(
                            "-framework",
                            "SingletonFramework",
                            "-F/Users/skwaj/Library/Developer/Xcode/DerivedData/iosApp-dhubylxzcqsleeamrwqbmhcxrxzj/Build/Products/Debug-iphonesimulator/"
                        )
                    }
                }

                binaries.all {
                    // Tell the linker where the framework is located.
                    linkerOpts(
                        "-framework",
                        "SingletonFramework",
                        "-F/Users/skwaj/Library/Developer/Xcode/DerivedData/iosApp-dhubylxzcqsleeamrwqbmhcxrxzj/Build/Products/Debug-iphonesimulator/"
                    )
                }
            }

            iosSimulatorArm64() {
                compilations.getByName("main") {
                    val DateTools by cinterops.creating {
                        // Path to .def file
                        defFile("src/iosMain/iOSWrapperFramework.def")

                        compilerOpts(
                            "-framework",
                            "SingletonFramework",
                            "-F/Users/skwaj/Library/Developer/Xcode/DerivedData/iosApp-dhubylxzcqsleeamrwqbmhcxrxzj/Build/Products/Debug-iphonesimulator/"
                        )
                    }
                }

                binaries.all {
                    // Tell the linker where the framework is located.
                    linkerOpts(
                        "-framework",
                        "SingletonFramework",
                        "-F/Users/skwaj/Library/Developer/Xcode/DerivedData/iosApp-dhubylxzcqsleeamrwqbmhcxrxzj/Build/Products/Debug-iphonesimulator/"
                    )
                }
            }

When I sync Gradle I get a lot of errors. Here is the part of the error message that I am getting:

Execution failed for task ':shared:cinteropDateToolsIosSimulatorArm64'.
> Could not resolve all files for configuration ':shared:iosSimulatorArm64DateToolsCInterop'.
   > Could not resolve com.google.android.material:material:1.6.1.
     Required by:
         project :shared
      > No matching variant of com.google.android.material:material:1.6.1 was found. The consumer was configured to find a usage of 'kotlin-cinterop' of a library, with the library elements 'cinterop-klib', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64' but:
          - Variant 'releaseApiPublication' capability com.google.android.material:material:1.6.1 declares an API of a library:
              - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, with the library elements 'cinterop-klib'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
          - Variant 'releaseRuntimePublication' capability com.google.android.material:material:1.6.1 declares a runtime of a library:
              - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, with the library elements 'cinterop-klib'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
          - Variant 'samplessources' capability com.google.android.material:material:1.6.1:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about its elements (required them with the library elements 'cinterop-klib')
                  - Doesn't say anything about its usage (required a usage of 'kotlin-cinterop')
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
   > Could not resolve androidx.appcompat:appcompat:1.4.2.
     Required by:
         project :shared
      > No matching variant of androidx.appcompat:appcompat:1.4.2 was found. The consumer was configured to find a usage of 'kotlin-cinterop' of a library, with the library elements 'cinterop-klib', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64' but:
          - Variant 'releaseVariantReleaseApiPublication' capability androidx.appcompat:appcompat:1.4.2 declares an API of a library:
              - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, with the library elements 'cinterop-klib'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
          - Variant 'releaseVariantReleaseRuntimePublication' capability androidx.appcompat:appcompat:1.4.2 declares a runtime of a library:
              - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, with the library elements 'cinterop-klib'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
          - Variant 'samplessources' capability androidx.appcompat:appcompat:1.4.2:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about its elements (required them with the library elements 'cinterop-klib')
                  - Doesn't say anything about its usage (required a usage of 'kotlin-cinterop')
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
          - Variant 'sourcesElements' capability androidx.appcompat:appcompat:1.4.2 declares a runtime of a component:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about its elements (required them with the library elements 'cinterop-klib')
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
   > Could not resolve androidx.constraintlayout:constraintlayout:2.1.4.
     Required by:
         project :shared
      > No matching variant of androidx.constraintlayout:constraintlayout:2.1.4 was found. The consumer was configured to find a usage of 'kotlin-cinterop' of a library, with the library elements 'cinterop-klib', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64' but:
          - Variant 'releaseApiPublication' capability androidx.constraintlayout:constraintlayout:2.1.4 declares an API of a library:
              - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, with the library elements 'cinterop-klib'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
          - Variant 'releaseRuntimePublication' capability androidx.constraintlayout:constraintlayout:2.1.4 declares a runtime of a library:
              - Incompatible because this component declares a component, with the library elements 'aar' and the consumer needed a component, with the library elements 'cinterop-klib'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')
          - Variant 'samplessources' capability androidx.constraintlayout:constraintlayout:2.1.4:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about its elements (required them with the library elements 'cinterop-klib')
                  - Doesn't say anything about its usage (required a usage of 'kotlin-cinterop')
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_simulator_arm64')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'native')

Here is a link to the full error message: https://pastebin.com/y5aqekj9.

Does anyone know what is going on? My framework's name is SingletonFramework I have set it to be this way in Xcode.

0 Answers
Related