react-native-maps: Expo SDK 51: AirGoogleMaps dir must be added to your xCode project to support GoogleMaps on iOS

Summary

After upgrading to Expo SDK 51, and using Expo Go, we receive the following error. We did not have this error with SDK 50.

WhatsApp Image 2024-05-09 at 09 40 33

Reproducible sample code

import MapView, { PROVIDER_GOOGLE } from 'react-native-maps'

<MapView
    provider={PROVIDER_GOOGLE}
/>

Steps to reproduce

Start an Expo SDK 51 project, with the managed flow. Run the app via Expo Go Use provider google

Expected result

The map renders

Actual result

We get an error, saying a native dependency is missing. But since this is Expo managed, it should be fixed with them.

React Native Maps Version

1.14.0

What platforms are you seeing the problem on?

iOS (Google Maps)

React Native Version

0.74.1

What version of Expo are you using?

SDK 48

Device(s)

iPhone SE 3 (simulator), iPhone 14 Pro Max (device)

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 45 (9 by maintainers)

Most upvoted comments

Hi there! Google Maps is no longer supported in Expo Go for iOS. You can use Apple Maps in Expo Go instead (remove the prop provider={PROVIDER_GOOGLE} from your <MapView /> components) or switch to a development build (recommended). If you have already configured Google Maps for your production releases, no additional configuration will be necessary. Learn how to set up a development build.

A few things to note about Expo Go:

  • Expo Go is intended to be a sandbox environment, and we recommend using development builds for any real app. The “Set up your environment” guide will help you get set up with a development build. We also have a full EAS tutorial if you want to learn more, and a concise video course that you can pick and choose lessons from as they are relevant to your use case.
  • Development builds give you full control over the native runtime (you can write native code or include any library you like), they are much closer to your production environment, and you can update SDK versions at whichever pace works for you.
  • You can still install Expo Go for any SDK version on Android emulators, Android devices, and iOS simulators. We’ve made the process for doing this as easy as possible on https://expo.dev/go.

I have a development build + Google Maps API key but I am still getting this error

@robinclaes - the decision was made because we are trying to reduce instances in Expo Go where behavior doesn’t immediately transfer over to a development build. in this case, you didn’t have to configure Google Maps to work in Expo Go because it used our Google API credentials, but when you create a development build or production build, it would no longer work and you would need to then create your own Google Maps credentials configure it. this is frustrating because it’s unexpected and at this point you’ll think you’ve already built support for maps, you may not have budgeted the time in for your release, or maybe you’ll just give up and go back to Expo Go. the state we’re moving towards is that, whenever possible, something that runs in Expo Go should run without changes in a development build.

@elisabeth0bangoura - I guess I have to switch to native because that was the only reason I used Expo… 😒

I’m not sure I understand your comment 😃 Expo is much more than the “Expo Go” app - the sandbox app for experimenting and learning. I encourage you to take a look at development builds - which are like a version of Expo Go that you have full control over.

Ultimately, if you prefer to use other tooling, you should do what is best for you!

I also have a development build with API key and get the error

For anyone encountering this and uses Expo, I wrote a config plugin https://www.npmjs.com/package/react-native-maps-expo-plugin to do this without you having to manually tweak files:

npm install react-native-maps-expo-plugin

Then add it to your app.json or app.config.js:

{
  "plugins": [
    [
      "react-native-maps-expo-plugin",
      {
        "googleMapsApiKey": "YOUR_GOOGLE_MAPS_API_KEY"
      }
    ]
  ]
}

Now you can generate the native code and build:

# Generate native code
npx expo prebuild

# Build and run on iOS
npx expo run:ios

# Or if using CNG workflow, use --clean to safely regenerate native files
npx expo prebuild --clean
npx expo run:ios
What is CNG?

Continuous Native Generation (CNG) is a process for building an Expo app where your native projects are generated on-demand from your app.json and package.json, similar to how your node_modules are generated from your package.json.

You can add the native project directories (android and ios) to your .gitignore and/or delete the project at any time, then re-generate them from the Expo app config with npx expo prebuild whenever required. You might never even run prebuild on your own development machine if you use a cloud-based development workflow.

Using CNG can make upgrading to new versions of React Native much easier. It can simplify project maintenance and facilitate setting up complex features such as App Clips, share extensions, and push notifications. This is all made possible with config plugins. Learn more about CNG.

Why this is better than tweaking the generated native files yourself:

Here’s Expo documentation on why tweaking the files yourself is not a good idea: https://docs.expo.dev/workflow/overview/#what-if-i-want-to-edit-the.

In summary, the official react-native-maps installation requires manual modifications to native iOS files that get wiped out when using CNG (npx expo prebuild --clean). This plugin automatically handles:

  • Adding Google Maps pod to Podfile
  • Adding location permission to Info.plist
  • Initializing Google Maps in AppDelegate

In other words, it will do the react-native-maps installation instructions for you every time, so you can keep enjoying CNG!

image

I also have a development build with API key and get the error

You guys should reconsider your choice to remove Google Maps for IOS. Apple maps cannot be styled and with google maps not working. I don’t think theres a way to theme the app with the rest of the app. Light mode maps/dark mode maps etc.

I was able to use Google maps. But I had to npx expo prebuild then I just followed the docs as if I were using a RN CLI.

Can you provide more info? Still getting the same error. You on Expo v 51?

Once you run npx expo prebuild, it will generate the folders for both Android and iOS then just follow this doc - https://github.com/react-native-maps/react-native-maps/blob/master/docs/installation.md

I agree with @jmejiamu—running Google Maps with react-native-maps in Expo command no longer works as expected. To resolve this, I ran:

npx expo prebuild

Next, I opened ios/MyProject.xcworkspace in Xcode, navigated to the AppDelegate.mm file, and added my Google Maps API key following the instructions in the react-native-maps installation guide.

After launching the app from Xcode to the simulator, Google Maps rendered correctly.

I’m also directly using development build, not Expo Go, but got hit with the same error. @WayneJWZLemon’s fix worked for me. To further add onto the description:

  1. After npx expo prebuild and adding the necessary lines mentioned in the guide, you could be prompted with the error 'GoogleMaps/GoogleMaps.h' file not found. To fix this, go to your Podfile (in the .iOS folder created by prebuild) and add pod 'GoogleMaps'.
  2. Combining with the instructions mentioned in the guide, what’s actually needed is
  # React Native Maps dependencies
  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-google-maps', :path => rn_maps_path
  pod 'GoogleMaps'
  pod 'Google-Maps-iOS-Utils'

and it should be added before the function call use_native_modules

So in my case, the code looks like

target 'MyProject' do
  use_expo_modules!
  
  # React Native Maps dependencies
  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-google-maps', :path => rn_maps_path
  pod 'GoogleMaps'
  pod 'Google-Maps-iOS-Utils'

  config = use_native_modules!
  
  use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
  use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS']

after adding the snippet.

This helped fixing the issue for me.

  • Note: The platform version (at least 14, mentioned in the installation guide) does make a difference. Make sure to add that as well.

I agree with @jmejiamu—running Google Maps with react-native-maps in Expo command no longer works as expected. To resolve this, I ran:

npx expo prebuild

Next, I opened ios/MyProject.xcworkspace in Xcode, navigated to the AppDelegate.mm file, and added my Google Maps API key following the instructions in the react-native-maps installation guide.

After launching the app from Xcode to the simulator, Google Maps rendered correctly.

@jmejiamu Thank you ! 🚀

Yeah because for me, I’m doing like a multi app setting, so I need 2 apps open at the same time. Just was easier that way, but meh, can simple just do a constants check if in __DEV__ to use not use google maps provider and just have production / dev builds use google.

❤️

That’s crazy. Picture using development build on simulator on your laptop then expo go on your phone.

Lol this just made things way more complicated. Damn. Thanks for the update tho!

I have the same issue.

Default provider works fine on my apple device but renders Apple Maps

I have the same issue, is there any way to fix it?

Just read de docs and follow the steps.

My problem was that I used npx expo prebuild --clean and lost my previous config https://docs.expo.dev/versions/latest/sdk/map-view/

Hi there! Google Maps is no longer supported in Expo Go for iOS. You can use Apple Maps in Expo Go instead (remove the prop provider={PROVIDER_GOOGLE} from your <MapView /> components) or switch to a development build (recommended). If you have already configured Google Maps for your production releases, no additional configuration will be necessary. Learn how to set up a development build.

A few things to note about Expo Go:

  • Expo Go is intended to be a sandbox environment, and we recommend using development builds for any real app. The “Set up your environment” guide will help you get set up with a development build. We also have a full EAS tutorial if you want to learn more, and a concise video course that you can pick and choose lessons from as they are relevant to your use case.
  • Development builds give you full control over the native runtime (you can write native code or include any library you like), they are much closer to your production environment, and you can update SDK versions at whichever pace works for you.
  • You can still install Expo Go for any SDK version on Android emulators, Android devices, and iOS simulators. We’ve made the process for doing this as easy as possible on https://expo.dev/go.

@brentvatne thanks, anywhere where we can read up on the decision to remove this from Expo Go? Interested to know the Why.

I guess I have to switch to native because that was the only reason I used Expo… 😒

I’m facing the same issue. Version 50 worked perfectly… and iOS is forcing an update to version 51.