Hello in our kmp project, we’re moving away from u...
# touchlab-tools
j
Hello in our kmp project, we’re moving away from using cocoapods to using spm. is there a way via kmmbridge to generate the dependencies in the Package.swift, similar to how we define pod dependencies in the gradle file to generate the dependencies in the podspec?
k
If you mean similar to how the Kotlin CocoaPods plugin configures cinterop such that you can use native dependencies in your project and call them from your Kotlin code, no. There is no formal/official support for that, and we never made any attempt to implement it in KMMBridge. It would be rather complex, and I made the gamble that it would be something the Kotlin team would want/need to do at some point. There is a library that is intended to do that: https://github.com/frankois944/spm4Kmp. I haven't been able to evaluate it myself, nor use it in the context of KMMBridge, but
spm4Kmp
can wrap SPM dependencies and configure cinterop for them, then there's no major reason why it couldn't be used with KMMBridge. However, you'll almost certainly need to disable the automatic
Package.swift
feature of KMMBridge because I'm sure
spm4Kmp
will need to at least use it, if not change the file itself. Again, I've never used
spm4Kmp
, so I don't know whether it actually changes
Package.swift
or not, but to define SPM dependencies, you'll need them in
Package.swift
at a minimum, so I can't imagine it would play well with default KMMBridge functionality.
j
thank you!
f
Hi, if you have any question about spmforkmp, I’m still around this slack 🙂
j
Oh yes, thanks for reaching out :) I’ve stumbled upon an issue with our multi module setup. So we have an umbrella module, which has references to different child modules. Each of the child modules has their spm dependencies defined via spm4kmp. However, i only want to generate the Package.swift for the umbrella module. Is there any built in way I could get references to the modules defined from the child modules so I could aggregate the dependencies into one Package.swift file in the umbrella module? I would like to end up with something like this:
Copy code
// Package.swift

let package = Package(
  name: "UmbrellaModule",
  platforms: [
    .iOS(.v16),
    .watchOS(.v9)
  ],
  products: [
    .library(
      name: "UmbrellaModule",
      targets: ["UmbrellaModule", "UmbrellaModuleDependencies"]
    )
  ],
  dependencies: [
    .package(url: "<https://github.com/firebase/firebase-ios-sdk.git>", .upToNextMajor(from: "12.0.0")),
    .package(url: "<https://github.com/googleads/swift-package-manager-google-mobile-ads.git>", .upToNextMajor(from: "12.0.0"))
  ],
  targets: [
    .binaryTarget(
      name: "UmbrellaModule",
      url: <url>, // generated by kmmbridge
      checksum: <checksum> // generated by kmmbridge
    ),
    .target(
      name: "UmbrellaModuleDependencies",
      dependencies: [
        .product(name: "FirebaseAnalytics", package: "firebase-ios-sdk"), // dependency of module A
        .product(name: "FirebaseRemoteConfig", package: "firebase-ios-sdk"), //dependency of module B
        .product(name: "GoogleMobileAds", package: "swift-package-manager-google-mobile-ads") // dependency of module C
      ],
      path: "Sources"
    )
  ]
)
f
I’m not sure about your module organization, But I think you should aim for the local package (to be added inside the dependencies array) Each module who require a local package has one (generated by the plugin) and they can be gathered inside your umbrella Package.swift. FYI, the local package could be replaced by a remote package
j
thanks will try it out 😄
❤️ 1
f
If you have any others questions, consider to open a discussion of the GitHub project :)
j
can I ask one more question? I see this from the example app, that you are able to generate the Package.swift from the exportedNativeIosShared. How do you do this? mine is always generated inside the build folder
f
the Package.swift inside the build folder and the one inside the exported are not the same. • The first is for building the bridge and dependency • The second is for completing the missing content require by xcode. See this https://spmforkmp.eu/references/exportedPackageConfig/
The exportedNativeIosShared is the equivalent of the project generated by cocoapods
actually, you only need to work with the generated local package
j
aaah thank you! was able to generate it
🙌 1