react-native-maps: ios build fails on v1.22.6 - RN 0.79.1 - new architecture disabled

Summary

ios build fails:

Reproducible sample code

<MapView />

Steps to reproduce

  • Use se the provided /example project:
  • RCT_NEW_ARCH_ENABLED=0 pod install in /ios
  • XCode build

Expected result

ios build completes

Actual result

See screenshot attached.

React Native Maps Version

From 1.22.0…1.22.6

What platforms are you seeing the problem on?

iOS (Apple Maps), iOS (Google Maps)

React Native Version

0.79.1, Fabric disabled: RCT_NEW_ARCH_ENABLED=0

What version of Expo are you using?

Not using Expo

Device(s)

simulator

Additional information

Pod install ✅

Pod install took 47 [s] to run
🔧 Patched @import in: /app/ios/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMSMarker+GMUClusteritem.h
🔧 Patched @import in: /app/ios/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUGeoJSONParser.h
🔧 Patched @import in: /app/ios/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUPolygon.h
🔧 Patched @import in: /app/ios/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUWeightedLatLng.h
🔧 Patched @import in: /app/ios/Pods/GoogleMaps/Maps/Sources/GMSEmpty.h
Integrating client project
Pod installation complete! There are 112 dependencies from the Podfile and 148 total pods installed.

Compilation ❌

Image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 19
  • Comments: 79 (4 by maintainers)

Most upvoted comments

For everyone else stumbling on this issue you need to update your podfile:

rn_maps_path = '../node_modules/react-native-maps'
pod 'react-native-maps', :path => rn_maps_path
pod 'react-native-google-maps', :path => rn_maps_path
pod 'react-native-maps-generated', :path => rn_maps_path

Nevermind @gusparis. I’ve already found the fix. It was just a case of reading the Podfile of the example project.

You need to add the following to the Podfile:


    # Replace @import GoogleMaps; with #import <GoogleMaps/GoogleMaps.h> in specific files
    specific_files = [
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMSMarker+GMUClusteritem.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUGeoJSONParser.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUPolygon.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUWeightedLatLng.h",
      "#{Pod::Config.instance.installation_root}/Pods/GoogleMaps/Maps/Sources/GMSEmpty.h"
    ]

    specific_files.each do |file|
      if File.exist?(file)
        text = File.read(file)
        if text.include?("@import GoogleMaps;")
          new_text = text.gsub("@import GoogleMaps;", "#import <GoogleMaps/GoogleMaps.h>")
          File.open(file, "w") { |f| f.write(new_text) }
          puts "🔧 Patched @import in: #{file}"
        else
          puts "ℹ️ No @import GoogleMaps; found in: #{file}"
        end
      else
        puts "⚠️ File not found: #{file}"
      end
    end

Right beneath:

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )

Perhaps, it’s a good idea to update the installation instructions for use with Fabric support.

@gusparis It didn’t work. For reference, I created a brand new project using the new architecture and RN 0.79.0 (Not using expo).

Podfile is the following:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'Maps' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-maps', :path => rn_maps_path
  pod 'react-native-google-maps', :path => rn_maps_path
  pod 'react-native-maps-generated', :path => rn_maps_path

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
  end
end

I installed it like this:

yarn add react-native-maps@1.21.0
cd ios && npx pod install

Opened Xcode afterwards to build, which results in the following error:

Use of '@import' when C++ modules are disabled, consider using -fmodules and -fcxx-modules in the file Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUWeightedLatLng.h

And I keep getting this issue while installing pod files, I added the lines from above, also on a new created expo project.

❌ (/my-app/ios/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUWeightedLatLng.h:19:1)

17 | 18 | #import <CoreLocation/CoreLocation.h>

19 | @import GoogleMaps; | ^ use of ‘@import’ when C++ modules are disabled, consider using -fmodules and -fcxx-modules 20 | 21 | NS_ASSUME_NONNULL_BEGIN 22 |

Same issue here: "Use of ‘@import’ when C++ modules are disabled, consider using -fmodules and -fcxx-modules" on react native: 0.78.2 and “react-native-maps”: “1.22.6”.

Have you try this

The solution to update the Podfile is not ideal if you are using Continuous Native Generation (CNG) with Expo right? Since the idea is to add your native folders to .gitignore.

I have the same issue as @kstolk.

I am using:

"react-native": "0.79.1",
"react-native-maps": "^1.22.6",

Pod file: As mentioned in the official docs here

rn_maps_path = '../node_modules/react-native-maps'
pod 'react-native-maps', :path => rn_maps_path
pod 'react-native-google-maps', :path => rn_maps_path
pod 'react-native-maps-generated', :path => rn_maps_path
post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )

    # Replace @import GoogleMaps; with #import <GoogleMaps/GoogleMaps.h> in specific files
    specific_files = [
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMSMarker+GMUClusteritem.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUGeoJSONParser.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUPolygon.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUWeightedLatLng.h",
      "#{Pod::Config.instance.installation_root}/Pods/GoogleMaps/Maps/Sources/GMSEmpty.h"
    ]

    specific_files.each do |file|
      if File.exist?(file)
        text = File.read(file)
        if text.include?("@import GoogleMaps;")
          new_text = text.gsub("@import GoogleMaps;", "#import <GoogleMaps/GoogleMaps.h>")
          File.open(file, "w") { |f| f.write(new_text) }
          puts "🔧 Patched @import in: #{file}"
        else
          puts "ℹ️ No @import GoogleMaps; found in: #{file}"
        end
      else
        puts "⚠️ File not found: #{file}"
      end
    end
  end

This worked for me

@angelica-snowit @LPitonakova the pod references changed; i.e. this is my latest successful iOS build config using RN 0.79.2 and RN maps 1.23.8:

  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-maps/Google', :path => rn_maps_path

hey whoever facing this issue with latest react native just do this first add this in pod file rn_maps_path = ‘…/node_modules/react-native-maps’ pod ‘react-native-maps’, :path => rn_maps_path pod ‘react-native-google-maps’, :path => rn_maps_path pod ‘react-native-maps-generated’, :path => rn_maps_path then make build with Xcode …when it fails go to specific error file and change(in my case I got error in Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUWeightedLatLng.h file) //@import GoogleMaps; replace this with below line #import <GoogleMaps/GoogleMaps.h> this will work

Same issue here: "Use of ‘@import’ when C++ modules are disabled, consider using -fmodules and -fcxx-modules" on react native: 0.78.2 and “react-native-maps”: “1.22.6”.

@MadeinFrance Downgrade react-native-maps to v1.20.1. It worked for me

Nevermind @gusparis. I’ve already found the fix. It was just a case of reading the Podfile of the example project.

This fixed it for me in expo. Both the code you provided and adding the custom pod specs.

Temporary custom expo plugin for these fixes!

If you’re using expo it’ll probably overwrite your Podfile everytime you rebuild or use eas to ship your app. So i made a temporary plugin file you can add to your app.config to add these fixes. This should be seen as a temporary fix tho!

  1. Create a file called react-native-maps-fix-plugin.js in the root of your expo project with this code
const fs = require("fs");
const path = require("path");

const plugins = require("@expo/config-plugins");
const {
  removeContents,
  mergeContents,
} = require("@expo/config-plugins/build/utils/generateCode");

// The Google Maps import fix
const googleMapsPodfileFix = `
    # Replace @import GoogleMaps; with #import <GoogleMaps/GoogleMaps.h> in specific files
    specific_files = [
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMSMarker+GMUClusteritem.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUGeoJSONParser.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUPolygon.h",
      "#{Pod::Config.instance.installation_root}/Pods/Google-Maps-iOS-Utils/Sources/GoogleMapsUtilsObjC/include/GMUWeightedLatLng.h",
      "#{Pod::Config.instance.installation_root}/Pods/GoogleMaps/Maps/Sources/GMSEmpty.h"
    ]

    specific_files.each do |file|
      if File.exist?(file)
        text = File.read(file)
        if text.include?("@import GoogleMaps;")
          new_text = text.gsub("@import GoogleMaps;", "#import <GoogleMaps/GoogleMaps.h>")
          File.open(file, "w") { |f| f.write(new_text) }
          puts "🔧 Patched @import in: #{file}"
        else
          puts "ℹ️ No @import GoogleMaps; found in: #{file}"
        end
      else
        puts "⚠️ File not found: #{file}"
      end
    end`;

// The custom react-native-maps pod entries
const customMapsPodsEntries = `
# Custom react-native-maps configuration
rn_maps_path = '../node_modules/react-native-maps'
pod 'react-native-maps', :path => rn_maps_path
pod 'react-native-maps-generated', :path => rn_maps_path
`;

module.exports = function withReactNativeMapsCustomization(config) {
  return plugins.withDangerousMod(config, [
    "ios",
    async config => {
      const filePath = path.join(
        config.modRequest.platformProjectRoot,
        "Podfile"
      );
      let contents = fs.readFileSync(filePath, "utf-8");

      // Step 1: Add custom pods after use_native_modules!
      const removeOldPods = removeContents({
        tag: "custom-react-native-maps-pods",
        src: contents,
      });

      const addCustomPods = mergeContents({
        tag: "custom-react-native-maps-pods",
        src: removeOldPods.contents,
        newSrc: customMapsPodsEntries,
        anchor: /config = use_native_modules!\(config_command\)/,
        offset: 1,
        comment: "#",
      });

      if (!addCustomPods.didMerge) {
        console.log(
          "ERROR: react-native-maps-fix-plugin.js: Cannot add custom react-native-maps pods to the project's ios/Podfile. Could not find 'use_native_modules!' call."
        );
        console.log(addCustomPods);
        return config;
      }

      // Step 2: If previous build already has modified this, remove the old Google Maps fix
      const removeOldFix = removeContents({
        tag: "react-native-maps-import-fix",
        src: addCustomPods.contents,
      });

      // Step 3: Add our Google Maps fix after the react_native_post_install call
      const enableFix = mergeContents({
        tag: "react-native-maps-import-fix",
        src: removeOldFix.contents,
        newSrc: googleMapsPodfileFix,
        anchor: /react_native_post_install\(/,
        offset: 6, // Position after the closing ")" and subsequent line(s)
        comment: "#",
      });

      if (!enableFix.didMerge) {
        console.log(
          "ERROR: react-native-maps-fix-plugin.js: Cannot add Google Maps import fix to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile."
        );
        console.log(enableFix);
        return config;
      }

      fs.writeFileSync(filePath, enableFix.contents);
      console.log(
        "✅ Added custom react-native-maps pods and Google Maps import fix to Podfile"
      );

      return config;
    },
  ]);
};
  1. Add this line to your app.config.json expo.plugins "./react-native-maps-fix-plugin"

Now it should add the fixes mentioned here everytime you rebuild your ios directory ✌️

this is such a mess, jesus christ.

This now should be fixed with the latest release v1.23.0

it took too much effort trying to get the lib migrated to monorepo to avoid all the hacks around pods, babel, metro … but I couldn’t get it working with semantic-release/npm

anyhow at least now we have a single podspec file that should allow generated pod to be included without it being manually linked.

@SKHRAPP please remove the carat ‘^’ before version … it is for targeting higher version than given so remove that and try to do the rest

If we don’t have any effective solution yet, I have small trick downgrading react-native-maps version to 1.20.1 remember remove ‘^’ symbol in package.json 😃, remove node_modules and pod deintegrate is also necessary. If you guy downgrade successful, we don’t need to add anykind of new code in Podfile just revert and follow the installation steps on the instruction and everything is ok.

I’m using:

  • RN - 0.77
  • react-native-maps: 1.20.1

Remember my solution is just temporary and for anyone who don’t need to use new feature in react-native-maps version.

@fedpre yes remove the import google maps instead replace it with #import <GoogleMaps/GoogleMaps.h> just changing the format of importing worked out for me

If you have the old arch and still facing issue then please check dependenacy is having caret sign like “react-native-maps”: “^1.15.6”, and if so remove it do install using yarn add react-native-maps@1.15.6 for example.

Image Same issue here
Image

Getting Error after adding the below code in podfile !!

rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-maps', :path => rn_maps_path pod 'react-native-google-maps', :path => rn_maps_path pod 'react-native-maps-generated', :path => rn_maps_path

Also Added the code that @mHvNG suggested above.

Any Idea why this is so ?

For everyone else stumbling on this issue you need to update your podfile:

rn_maps_path = '../node_modules/react-native-maps'
pod 'react-native-maps', :path => rn_maps_path
pod 'react-native-google-maps', :path => rn_maps_path
pod 'react-native-maps-generated', :path => rn_maps_path

Issue solved ✅

Thank you all for your insights.

I’m using expo and encounter the exact same message… Any idea how to fix this there? The pod based approach is getting overwritten by expo on prebuild.

@gusparis same issues:

Image

@salah-ghanim I experience the issue on /master latest commit using Cocoapods 1.14.3 targeting iOS sim 18.4 on XCode 16.2

Q:

  1. Is the example project building fine on your side?
  2. Is the file RNMapsMapView.mm correctly edited after pod install (screenshot below)
Image

@SKHRAPP just downgrade to 1.20.1 while the issue persist please

When I run from terminal and build in xcode, it is okay working no problem, but when i try to archive, I face the problem saying

Showing All Errors Only Target ‘React-Core-f955c501-React-Core_privacy’ (project ‘Pods’) has create directory command with output ‘Library/Developer/Xcode/DerivedData/googleMaps-dgpsomhuctxnfvdtdboprqhjywtu/Build/Intermediates.noindex/ArchiveIntermediates/googleMaps/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/React-Core_privacy.bundle’

Showing All Errors Only Target ‘React-Core.common-React-Core_privacy’ (project ‘Pods’) has create directory command with output ‘Library/Developer/Xcode/DerivedData/googleMaps-dgpsomhuctxnfvdtdboprqhjywtu/Build/Intermediates.noindex/ArchiveIntermediates/googleMaps/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/React-Core_privacy.bundle’

there is no any copied bundle file to delete in build phase

I tried so many ways, it is impossible to solve this issue, i can’t archive and upload my app to app connect. any way to solve this issue. I tried in brend new project and existing one.

@nahuelprinsich you need to add this code here https://github.com/react-native-maps/react-native-maps/issues/5400#issuecomment-2798827292 and it will go away

My issue is that adding that code I then have another problem after the build completes 😢

@gusparis Doesn’t help either. I’ve removed the Podfile.lock file, deleted pods folder to be safe and cleaned the build folder and I still get the error when I moved the pods before use_native_modules.

Edit: And executed the pod cache clean --all command.

hey @MadeinFrance! yeah, like I commented before that solves pod install issue, but then later the app is not running (at least for me). Did you make it to run?

@salah-ghanim I think this is related to your comment about autolinking. I tried installing without the changes to the Expo config plugin, but I had to manually change it to add the generated pod to Podfile to make it work. Do you think there’s a way to fix this in react-native-maps, or should we update the upstream Expo plugin for this?

I confirmed that this is happening for me as well (non-Expo project), even on a brand new React Native cli project. I had to do the recommended pod file patch fix as found by @Jamal-Ud-Din-hub . That worked for me (I also had to add sudo file edit permissions from my command line in order for those files to be edited with a npx pod-install.

I would not recommend editing the files yourself in Xcode, because then all of your teammates would have to do this, and also any automated CI builds you have would not be able to do that, so they would fail.

@quentin23soleil it is. Just check out the installation instructions. https://github.com/react-native-maps/react-native-maps/blob/master/docs/installation.md

You now have to add the plugin manually to your app config. This changed in the Fabric architecture update, because Expo team wanted to move the plugin maintenance downstream to this repository, rather than have it built-in to Expo. Which makes sense, cause when there are breaking changes like this it’s easier to use the plugin that’s part of the react-native-maps package and menat to work with that version, rather than try to synchronize the react-native-maps version and expo version so that you have the right (hidden/default) plugin.

Sorry but do we have another solutions I try the @mHvNG solution but I still get a tons of RNMapsMarkerView, I’m using

Non Expo RN: 0.77 react-native-maps: 1.20.1

Small trick like remove node_modules, Pod, Podfile.lock; pod deintegrate doesn’t work too 😦((

@nahuelprinsich you need to add this code here #5400 (comment) and it will go away

My issue is that adding that code I then have another problem after the build completes 😢

It works, thanks!

Nevermind @gusparis. I’ve already found the fix. It was just a case of reading the Podfile of the example project.

You need to add the following to the Podfile:

Perhaps, it’s a good idea to update the installation instructions for use with Fabric support.

That was it! Thank you!

for @kstolk @spyshower and @mHvNG, delete Podfile.lock and do pod cache clean --all then pod install --repo-update. that should get the install done. as for us @MadeinFrance, I’m stuck at that point, had to revert back to 1.20.1 and specify Map version like Google was requiring to bypass their check