g0dkar / qrcode-kotlin

QRCode Generator implemented in pure Kotlin
https://qrcodekotlin.com/
MIT License
172 stars 16 forks source link

Native target support for KMM project #23

Closed arturschwarz closed 10 months ago

arturschwarz commented 1 year ago

Hi @g0dkar!

Are you planning on adding native target support for this project to be able to use it in a KMM project (more specifically Android & iOS KMM project)?

We've found that using the kotlin-only dependency (io.github.g0dkar:qrcode-kotlin:3.2.0) in our project results in the following error:

No matching variant of io.github.g0dkar:qrcode-kotlin:3.2.0 was found. The consumer was configured to find a usage of 'kotlin-api' of a library, 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_arm64' but:
          - Variant 'jvmApiElements-published' capability io.github.g0dkar:qrcode-kotlin:3.2.0 declares an API of a library:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - 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_arm64')

Thank you in advance!

g0dkar commented 1 year ago

Heya!

I absolutely can and will implement this ^^

Out of curiosity (and just to be 100% sure I got what you're asking): you are implementing a KMM project yourself, and you'd like to add this library as a dependency is that it?

Or is it a iOS KMM project? (which, in the end, will target "native")

arturschwarz commented 1 year ago

Thank you for your reply! Sounds great!

I'm working on a project which shares code between Android and iOS and is a Kotlin Multiplatform project. We've wanted to include your library to enable rendering the qr code in our shared part of the project. I hope this makes it as clear for you as possible!

g0dkar commented 1 year ago

Hey @arturschwarz, sorry for taking so long with this. Life got on the way on more ways than I could have imagined.

I've launched v3.3.0 recently which did much of the groundwork for your request :)

Native target was added, it is being built and all, but isn't implemented yet.

I'll start the actual implementation this week ^^

Any pointers on iOS PNG rendering are greatly appreciated 😁 (Can libpng be used? If it can, how? That's the first thing I'll investigate when I start :P)

realh commented 1 year ago

I would also like to use this in a KMM application. Swift and Objective C are really easy to interop with C, so it should be possible to use libpng. But I think the "correct" way to do that would be to add it as a dependency of the iOS part of the project rather than bundle libpng with this library. That's possible in KMM with a Cocoapods plugin, but I really don't want to have to use that. There is an unofficial alternative plugin which supports Swift Package Manager, but I haven't checked that out, so I don't know how reliable it is.

The iOS Kotlin module in a KMM app has access to Apple's Foundation library, so it would probably be better to use a bitmap format from CoreGraphics for the iOS part. In fact, CoreImage/CoreGraphics includes a basic QR generator itself, so in the meantime I can use that for iOS, and qrcode-kotlin just for Android.

AYastrebov commented 11 months ago

@g0dkar any updates on that?

g0dkar commented 11 months ago

Heya! Sort of, I've been way busy at work and at life in general.

Good news is: I now kind of know what I need to do ^^ Bad news is: I now kind of know what I need to do πŸ˜…

I'm almost there at having a working version with iOS. The main issue, for me, is testing it out. I'm really out of my depth with creating an iOS App to test it and all.

But I'll have news about this one soon (not "Soon(tm)" hehe)

g0dkar commented 10 months ago

Heya, just to give you an update on this: I'm almost understanding all I have to do to be able to build this for iOS hahaha

Sorry for the long delay, life is a mess right now.

I expect to have it by next week tops πŸ˜€

g0dkar commented 10 months ago

Btw is making the lib available via CocoaPods good for you all? I was just reading about how to make it available there ^^

It seems to me that adding a lib that's not there on an iOS project is quite a PITA πŸ˜…

g0dkar commented 10 months ago

Hey everyone! @ for notifications: @AYastrebov @realh @arturschwarz

I've opened this PR for iOS Support. Could any of you take a look? I'm really uncertain that's implemented as it should, but it is something πŸ˜…

I'll keep the PR open and updated until the 3rd or 4th of November.

I'll be a bit off this week so I won't be able to dedicate as much as time to this as I want to, but as soon as I'm back, I'll merge it and start the publishing process ^^

https://github.com/g0dkar/qrcode-kotlin/pull/77