1

I am integrating Google Maps SDK for iOS into my Kotlin Multiplatform (KMP) project. Earlier I was using CocoaPods and everything was working. Now I migrated to Swift Package Manager (SPM) and removed Pod integration from my project.

I added GoogleMaps via SPM in Xcode like this:

https://github.com/googlemaps/ios-maps-sdk

❗ Problem

In my shared KMP module (iosMain), Google Maps symbols are NOT recognized unless I create a .def file and configure a manual cinterop. For example, without .def, this line fails in iosMain but the code works in XCode, I can build the app:

import platform.GoogleMaps.GMSMapView  // <- Unresolved

So I had to manually add this in build.gradle.kts:

iosTarget().compilations.getByName("main") {
    cinterops.create("GoogleMaps") {
        defFile("src/iosMain/kotlin/org/example/project/GoogleMaps.def")
    }
}

And I had to create this GoogleMaps.def file:

language = Objective-C
headers = <GoogleMaps/GoogleMaps.h>
linkerOpts = -framework GoogleMaps -ObjC

Now it works, but my question is:

Question

  1. If I am already using Swift Package Manager to add GoogleMaps to my iOS app, why do I still need a cinterop .def file in Kotlin Multiplatform to access Google Maps from iosMain?
  2. Is there a way to consume an SPM dependency directly in Kotlin Multiplatform without manually writing .def and cinterop config?

What I expect

  • Use SPM only (no CocoaPods)
  • Avoid .def + manual cinterop
  • Import Google Maps directly in iosMain
1
  • which version of KMP your are using? I tried the same way but not working Commented Nov 4 at 10:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.