Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to publish multiplatform library for iOS #9

Open
lammertw opened this issue Jun 19, 2023 · 2 comments
Open

Unable to publish multiplatform library for iOS #9

lammertw opened this issue Jun 19, 2023 · 2 comments

Comments

@lammertw
Copy link

I'm trying to build a multiplatform library that uses CryptoKit. I've implemented code similar to the KCrypto example. When building a framework for iOS or when running a test on the iOS simulator, everything works fine. However, since I'm building a library, I want to publish it. I've added the maven-publish plugin to my build.gradle.kts file.

Now when I run publishIosSimulatorArm64PublicationToMavenLocal (or any other iOS publish task) it fail because it cannot find the types from the swift file.

In my build.gradle.kt:

swiftklib {
    create("KCrypto") {
        path = file("native/KCrypto")
        packageName("com.mylib.objclibs.kcrypto")
    }
}

native/KCrypto/PublicKeyEncoder.swift:

import CryptoKit
import Foundation

@objc public protocol PublicKeyEncoder {
    @objc func encodePublicKey(decompressedKeyData: Data) -> Data
}

In a iOS specific Kotlin (located in src/iosMain/kotlin:

import com.mylib.objclibs.kcrypto.*

Generates the following error:

e: file:///Users/[path]/src/iosMain/kotlin/com/mylib/ObjcDataCipher.kt:7:26 Unresolved reference: objclibs

As mentioned, this error only occurs when publishing. The same code runs fine in other scenarios.

@kalinjul
Copy link
Contributor

kalinjul commented Dec 1, 2023

I'm currently working on a library that needs publishing as well and I'm not having the issue you mentioned. Also Using CryptoKit: https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/oidc-core

That said, your code looks just like mine...

@IlyaGulya
Copy link
Collaborator

Hello!
Publishing of KMP libraries containing native code is somewhat complicated at the moment and require additional steps for publisher, such as writing cocoapods or spm definitions and publishing XCFramework somewhere accessible to library users.
I'm currently making my own library using this plugin and once I'm done I will describe how to do it properly in a blog post.
I will return in this issue once it's done 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants