ttypic / swift-klib-plugin

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

Problems with imports #10

Open enoler opened 10 months ago

enoler commented 10 months ago

Hello, I am trying to create a Kotlin class based on the swift library facebook-sdk-ios to be able to use one of the native functions of the Facebook SDK.

I installed the package on XCode using the SwiftPackageManager following this instructions.

I followed the steps on the Readme of your plugin and I create inside native/Facebook a file Facebook.swift that looks like:

import FacebookCore
import Foundation

@objc public class FacebookSdk : NSObject {
    @objc public class func getAccessToken() -> String {
        return AccessToken.current
    }
}

However, when I try to build, it appears an error in the console saying:

error: no such module 'FacebookCore'
import FacebookCore
       ^

Is there a way to make the libraries to be imported correctly? Is it even possible to get what I need using your plugin? I don't actually know if this is in the scope of the plugin or I need to find another solution.

Thank you in advance!

hatteajay1212 commented 9 months ago

@enoler i have been coming across the same issue of imports.I am trying to use Alamofire library through cocoapods but getting the same issue of 'no such module Alamofire' for import 'Alamofire'.Have you found any solution for this problem ?

enoler commented 9 months ago

@enoler i have been coming across the same issue of imports.I am trying to use Alamofire library through cocoapods but getting the same issue of 'no such module Alamofire' for import 'Alamofire'.Have you found any solution for this problem ?

Sadly I did not manage to fix it. If you finally get it, please post it here.

hatteajay1212 commented 9 months ago

@enoler have you got any other plugin or library to overcome this problem ?

enoler commented 9 months ago

@enoler have you got any other plugin or library to overcome this problem ?

No, I did not, actually I postponed the problem to wait for an answer using this plugin

hatteajay1212 commented 9 months ago

@enoler thanks for the quick response, will post it here if i manage to fix it.

enoler commented 9 months ago

@hatteajay1212 I just saw in the comments of this link that is not supported yet but the creator of the plugin is thinking about adding it.

@ttypic Thanks for your work and looking forward for it, honestly if you get how to do it it will be a life changer in the KMM ecosystem.

ttypic commented 9 months ago

@enoler, @hatteajay1212 thank you very much for using the plugin! Right now I don't have enough time to improve this behavior. I hope to come back to this in a month or so. But any help will be very much appreciated.

yumiki commented 9 months ago

Hello @ttypic, I'd like to help, but I'm not familiar with how dependencies work for Swift . Could you recommend any resources or provide advice on where I can start learning about this topic?

RaedGhazal commented 7 months ago

Facing the same issue here, I was trying to use firebase analytics but apparently this is not possible 🙁

jershell commented 7 months ago

The plugin cant working with dependencies

codesplode commented 6 months ago

Hi @ttypic, thanks for your hard work on this plugin. I'm also looking to add some sort of support for using a swift dependency with some glue code in swift to make Kotlin multiplatform libraries that don't require separate steps for swift dependencies and copy/pasting files.

I'm not super familiar with the apple build processes for these things, but I'm considering a simply dependency file that does a git checkout of swift package into the native folder and seeing how heavy that is or how it behaves at least. If there is another strategy you recommend based on your knowledge such as a way to make the plugin aware of the dependency and able to enforce that swift package manager adds it in the project using the library, it would be appreciated and I'll happily share the code in the end if it succeeds. Just want to end up on the right path so it is usable for all of us.

markst commented 5 months ago

@codesplode to me what would make most sense is to be able to setup a swift package with it's own dependencies.

i.e:

let package = Package(
    name: "YourPackageName",
    dependencies: [
        .package(url: "https://github.com/facebook/facebook-ios-sdk.git", from: "16.3.1")
    ],
    targets: [
        .target(
            name: "YourPackageName",
            dependencies: ["FacebookCore"]),

which can easily be built to a binary using:

swift build

@ttypic I had wondered about creating a new issue relating to this possible feature, but keen to hear your thoughts?

markst commented 5 months ago

@ttypic actually taking a real superficial look at the way the plugin works, it seems that createPackageSwift actually creates and compiles the package in order to link? Seem it could be a really simple change in approach to expect the Package.swift to be defined as part of the plugin usage rather than CompileSwiftTask generating.