Hey folks - kicking off a project at work, in whic...
# multiplatform
j
Hey folks - kicking off a project at work, in which we need to build native SDKs. Thinking about using KMP for shared logic, and then depending on the KMP portion in the native SDKs, which will have platform specific logic*.* There's plenty of tutorials out there for building KMP apps, but not many for SDKs. Has anyone done this and can share overall experience?
b
working on this right now actually
using shared compose UI as well
j
Ah nice! have so many questions for you - first, how did you structure the code? KMP logic in it's own standalone repo, or a mega repo w/ Android + iOS + KMP code?
Second - Do your native SDKs depend directly on the source code of your KMP project, or do you build binaries and depend on those?
b
repo is SDK plus sample apps
sample iOS app depends on cocoapod (from a local path for development); sample android uses the local source
for iOS I ./gradlew sdkpodPublishDebugXCFramework and build it with xcode after
j
was just going to ask that. okay so KMP publishes local framework to cocoapod, then you consume that in the ios sample app
b
yep
Podfile for sample app is
j
Do you have a native SDK layer between the sample app and KMP library?
b
Copy code
target 'sample-ios' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  platform :ios, '15.0'

  if ENV.include?("LOCAL_KOTLIN_PATH")
     pod 'BotStacksSDK', :path => ENV["LOCAL_KOTLIN_PATH"]
  else
    pod 'BotStacksSDK', '0.0.1'
  end
end
๐Ÿ™Œ 1
not at the moment
our "SDK" is a fully encompassing viewcontroller for both platforms
drop into existing app sort of thing
navigate to it and it runs
trying to see if I can bundle swift structs with the SDK to cleanup the footprint for iOS devs but havent had luck ywet
๐Ÿ‘ 1
yt*
yet**
e.g to abstract this
Copy code
struct BotStacksChatController : UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> UIViewController {
        let vc = BotStacksChatControllerKt.BotStacksChatController(onLogout: {})

        return vc
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
    
}
j
Ah got it. My goal is to have a KMP project with has shared logic (networking), and then have two separate native SDKs that depend on the KMP side. I'll then have two sample apps that depend on the native SDKs (while KMP stays completely internal to the SDKs)
trying to see if I can bundle swift structs with the SDK to cleanup the footprint for iOS devs but havent had luck ywet
This is exactly why I plan to have the middle layer of native SDKs. iOS Swift SDK will abstract some of the annoying KMP <> objc issues for our iOS devs.
that + native UI
b
nice
like it
j
I built this entire abstraction layer at my old job - wish I open sourced it. Could have been helpful to both of us right now.
Is your project open source?
b
will be soon
j
@brandonmcansh would you be down for a 30 min chat? could chat through our SDK setups / bounce ideas off each other. (this week or next?)
p
There is plenty of SDKs too. I have a GitHub list but don't see how to get a shareable link. Below is a good library as an example to consume a service. https://github.com/MoviebaseApp/tmdb-kotlin
j
Nice, will check this out!
p
In regards to embed swift code in klibs, not sure if possible. I tried without success, I ended up using a separate swift package in GitHub which depends on the KMP lib interfaces and it also contains the implementations. The downside is users need to import both a KMP lib in the iOS umbrella module and a Swift Package in the swiftui App, a bit hacky TBH
j
@Pablichjenkov going through your readme. where is the instruction on how to include your SDK in an ios app?
p
Well I am not the author of that library, I just picked it randomly, I think is a pretty good example of an SDK
๐Ÿ‘ 1
Ah I see, I just realized they don't have examples of how to use it. Sorry about that. But in general you just place the dependency in commonMain and that is it.
j
All good - I was referring to the cocoapod / spm integration steps
but this is still helpful, i'll take a look
p
Ah ok, I really can't help with cocoapods. I haven't used it in a while.
j
All good, thanks for the insight!
๐Ÿ‘ 1
b
Looks like I have to actually support component usage as well @Jagtej Sodhi. Abstraction layer for iOS it is
๐Ÿ‘ 1
j
Nice! I think that'll be cleaner longer term (esp so you can abstract kotlin <> objc translation that doesn't work well with swift).
b
Yep yep
j
Your iOS abstraction layer will also be an SDK?
or building that logic directly into the app?
b
SDK
j
have you thought through that yet? swift package? framework?
b
hoping for a swift package
j
And you'll compile the KMP framework and add it as a dependency in your swift package?
^^ this is what I did in my old app. Had a build phase step that generated the framework, and then my ios app referenced the framework. That way, any time i made changes to the KMP source, I could test directly against it.
But with Swift package, it's not as straight forward
b
And you'll compile the KMP framework and add it as a dependency in your swift package?
was my plan ๐Ÿ™‚
j
How do you plan to compile against the KMP sources? Ideally I want to setup a dev environment where I can make changes to KMP source that immediately get reflected in the iOS SDK (without having to manually regenerate the framework each time). I guess I could write a script that does it automatically, but wondering if there's an easier way (like the build phase process I described above). Note: swift packages don't have build phase steps.
b
still up in the working
working on the component stability in my sample-app sandbox first and then tackling rebundling/abstraction
existing API layer I inherited is an eyesore
๐Ÿ˜ธ 1
๐Ÿซ  1
j
oof
no worries, loop me in when you get to it
i can let you know how my setup pans out
b
any updates by chance? Have to pivot to this to hopefully get these released in a beta fashion next week ๐Ÿ‘€
j
Somewhat, stuck on one thing. Want to jump on a huddle today? Can walk you through what I have.
b
yep whats your day look like