Hi. Did somebody integrate GoogleMaps into compose...
# compose-ios
c
Hi. Did somebody integrate GoogleMaps into compose multiplaform for iOS? Sould I use cocoapods, if so how to add this dependency for ios targer? build.gradle.kts
Copy code
koltin {
   cocoapods {
        summary = "Shared Module"
        homepage = "Link to the Shared Module homepage"
        version = "1.0.0"

        ios.deploymentTarget = "17.4"

        framework {
            baseName = "composeApp"
            isStatic = true
        }

        pod("GoogleMaps") {
            version = "8.4.0"
            extraOpts += listOf("-compiler-option", "-fmodules")
        }
    }
....
MapView.ios.kt
Copy code
@OptIn(ExperimentalForeignApi::class)
@Composable
actual fun MapView(modifier: Modifier) {
    UIKitView(
        modifier = modifier,
        factory = {
            GMSMapView()
        },
        update = {
        }
    )
}
Should do smth extra?
Build fails
Copy code
ld: warning: Could not find or use auto-linked framework 'GoogleMaps': framework 'GoogleMaps' not found
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_GMSMapView", referenced from:
       in ComposeApp[arm64][2](ComposeApp.framework.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
c
I have achieved this in my app “Fred’s Roadtrip Storyteller”, and I have a video series walking through the code design choices: https://github.com/realityexpander/FredsRoadtripStoryteller
K 3
c
@Chris Athanas I haven't looked yet, but does your app support clustering?
c
No, I could not get to the
GoogleMapsUtils
to work, some cinterop issue. I reported it and I am sure the Google Maps team is aware of the problem working on an update. I was expecting some announcement at Google I/O 2024, but nothing that I saw. Did you hear any announcements?
c
Nope. I'm pretty sad at the state of gmaps on iOS to be honest. So many issues. even without kmp 😭
👍 1
v
@Chris Athanas did you submit a bug report somewhere? Is there a way to check status for it?
m
@Chris Athanas -- I hate to revive an old thread, but was wondering if you had some details about the cInterop issue you faced? I currently have GoogleMapsUtils in my app running, but there its a bit wonky and I'm trying to work through the details. Basically, it imports as Google_Maps_iOS_Utils rather than the short name (whatever, I can live with that) and it requires I use the GMSMapView from the Util version rather than the Google Maps version (okay). But, it removes the markers and clusters as I interact with the map. So, I started trying to see what needed to be done and am trying to dig into seeing if it needs the interopBindingDependencies added to the gradle so that it correctly binds the GoogleMaps and the GoogleMapsUtils together (rather than having their own GMSView etc) as I noticed there are some individual items missing from the wrapped code and it doesn't have classes like GMUClusterItem but rather just the Protocol entries and such. Anyways, any info you've got on what you ran into may help, especially if this is the interop bug you're mentioning.
K 1
Chatted with a guy, got it worked out on the disappearing parts, going to get the rest of the stuff going -- if anyone is interested, I"ll post up snippets as they help
1
🚀 1
c
yes definteiyl. you should post something on github!
2
v
Can't wait for those snippets! Please share! 🙏
m
Yeah, I've got it fully tied together now with delegates and everything
I'm going to try and extract it to a github repo that can be an example without all of the excess of our app, etc.
🎉 1
I can double check that everything works later. I pulled a sample template and went from there. I'm hoping to update the readme and stuff. Lots of credit goes to the attached blogs. https://github.com/mdostal/ClusterExample It requires keys added to it and I tried to strip out a ton of the other logic, logins, viewModels and other things we had in there. This should be the base for clustering in compose + using google maps sdk for clusterintg (ios will have errors shown in the editor but they'll compile and run, KT doesn't do well with the ios overrides having the same base method signature) GitHub GitHub - mdostal/ClusterExample Contribute to mdostal/ClusterExample development by creating an account on GitHub.
Blog-Kudos.txt
If you want a full running one, I can make sure it fully builds both tomorrow -- android should build there atm and I've gotta fix up the gradle build files a bit I believe for the ios half of it atm (luckily this one isn't nearly as complex as my main repo with coil, firebase, etc tacked in)
v
Thanks man! You are a life saver! I think there's something we were all missing in build.gradle, after looking at your repo, I had all the exact same things, but still couldn't install cocoapods, but this somehow works 🤔
c
NICEEEE
m
double check the root gradle as well if the cocoapod plugin is failing
and cocoa pods have to follow the pod install stuff from the terminal separately as well. -- if you are missing the podspec, the repo I uploaded is probably missing part of the generate section for that as I hastily tossed stuff together. My podspec looks something like this:
Copy code
Pod::Spec.new do |spec|
    spec.name                     = 'composeApp'
    spec.version                  = '1.0'
    spec.homepage                 = 'Link to the Shared Module homepage'
    spec.source                   = { :http=> ''}
    spec.authors                  = ''
    spec.license                  = ''
    spec.summary                  = 'Some description for the Shared Module'
    spec.vendored_frameworks      = 'build/cocoapods/framework/ComposeApp.framework'
    spec.libraries                = 'c++'
    spec.ios.deployment_target    = '15.4'
    spec.dependency 'Google-Maps-iOS-Utils', '6.0.0'
    spec.dependency 'GoogleMaps', '9.0.0'
                
    if !Dir.exist?('build/cocoapods/framework/ComposeApp.framework') || Dir.empty?('build/cocoapods/framework/ComposeApp.framework')
        raise "

        Kotlin framework 'ComposeApp' doesn't exist yet, so a proper Xcode project can't be generated.
        'pod install' should be executed after running ':generateDummyFramework' Gradle task:

            ./gradlew :composeApp:generateDummyFramework

        Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)"
    end
                
    spec.xcconfig = {
        'ENABLE_USER_SCRIPT_SANDBOXING' => 'NO',
    }
                
    spec.pod_target_xcconfig = {
        'KOTLIN_PROJECT_PATH' => ':composeApp',
        'PRODUCT_MODULE_NAME' => 'ComposeApp',
    }
                
    spec.script_phases = [
        {
            :name => 'Build composeApp',
            :execution_position => :before_compile,
            :shell_path => '/bin/sh',
            :script => <<-SCRIPT
                if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then
                  echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\""
                  exit 0
                fi
                set -ev
                REPO_ROOT="$PODS_TARGET_SRCROOT"
                "$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \
                    -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \
                    -Pkotlin.native.cocoapods.archs="$ARCHS" \
                    -Pkotlin.native.cocoapods.configuration="$CONFIGURATION"
            SCRIPT
        }
    ]
    spec.resources = ['build/compose/cocoapods/compose-resources']
end
However, it normally is generated and I can dig in tonight to ensure the full gradle process is working in this template one -- if that helps
v
Has anyone else managed to make it work? I am not getting just a blank screen, do you maybe need to set google maps api code in some specific way since it seems it's using map from Utils library and not from google maps itself?
m
if you're getting a blank screen, go to your google api console and enable the api for ios as well
even if you created the ios API key and everything, you have to enable ios apis separately -- i had a white map as well with my markers until I did that
I think that there should be a way to better bind the libraries when loading with the kmp dependencies and say pod depends on etc to get the google and google maps utils to play better. However, I was not able to get the separation correct and so all of the libs swapped to using the utils implementation which overrides the default google maps for maps,markers,etc
v
I think I have bigger issues, my old implementation of Google Maps works, but this doesn't. I don't see the markers or anything related to it, just a blank screen. (When you have the wrong api Key you would see markers and some google related stuff). Are you using the latest CMP library?
m
The actual implementation I'm running, no, I get hard crashes on some of the updates atm -- running 8.3.2 agp 4.3.3 for all google maps, coil is 3.0.0-rc1(upgrade to non-rc is an error) -- compose-plugin 1.6.11, kotlin 2.0.0 ... pods GoogleMaps 9.0.0, Utils 6.0.0
🙏 1
there's a ton of other stuff including firebase, auth, etc, but that's the core of it.. if you want a full libs toml, lmk