expo: [SDK 48.0.1] iOS prebuild fails with react-native-maps (Google Maps)

Minimal reproducible example

https://github.com/pchmn/test-expo-sdk-48

Summary

When using expo sdk 48 with react-native-maps (with Google Maps) there is a bug at iOS prebuild.

If you set a Google Maps Api Key in app.json (ios.config.googleMapsApiKey) and run npx expo prebuild there is this error :

✖ Config sync failed
Error: [ios.appDelegate]: withIosAppDelegateBaseMod: Cannot add Google Maps to the project's AppDelegate because it's malformed. Please report this with a copy of your project AppDelegate.
Error: [ios.appDelegate]: withIosAppDelegateBaseMod: Cannot add Google Maps to the project's AppDelegate because it's malformed. Please report this with a copy of your project AppDelegate.
    at /Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+config-plugins@6.0.0/node_modules/@expo/config-plugins/build/ios/Maps.js:218:19
    at action (/Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+config-plugins@6.0.0/node_modules/@expo/config-plugins/build/plugins/withMod.js:201:29)
    at interceptingMod (/Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+config-plugins@6.0.0/node_modules/@expo/config-plugins/build/plugins/withMod.js:105:27)
    at action (/Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+config-plugins@6.0.0/node_modules/@expo/config-plugins/build/plugins/createBaseMod.js:61:27)
    at async interceptingMod (/Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+config-plugins@6.0.0/node_modules/@expo/config-plugins/build/plugins/withMod.js:105:21)
    at async evalModsAsync (/Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+config-plugins@6.0.0/node_modules/@expo/config-plugins/build/plugins/mod-compiler.js:204:25)
    at async Object.compileModsAsync (/Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+config-plugins@6.0.0/node_modules/@expo/config-plugins/build/plugins/mod-compiler.js:124:10)
    at async configureProjectAsync (/Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+cli@0.6.1_6weo4dzsrefthwodkc5gdxxcii/node_modules/@expo/cli/build/src/prebuild/configureProjectAsync.js:54:15)
    at async prebuildAsync (/Users/paul/Dev/perso/test-expo-sdk-48/node_modules/.pnpm/@expo+cli@0.6.1_6weo4dzsrefthwodkc5gdxxcii/node_modules/@expo/cli/build/src/prebuild/prebuildAsync.js:83:9)

If you remove ios.config.googleMapsApiKey of app.json, prebuild is working fine.

The problem seems to come from MATCH_INIT regex in Maps config plugin of @expo/config-plugins:

// Match against `UMModuleRegistryAdapter` (unimodules), and React Native without unimodules (Expo Modules), and SDK +44 React AppDelegate subscriber.
export const MATCH_INIT =
  /(?:(self\.|_)(\w+)\s?=\s?\[\[UMModuleRegistryAdapter alloc\])|(?:RCTBridge\s?\*\s?(\w+)\s?=\s?\[\[RCTBridge alloc\])|(\[self\.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions\])/g;

Environment

expo-env-info 1.0.5 environment info: System: OS: macOS 13.1 Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.0/bin/yarn npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 IDEs: Android Studio: 2022.1 AI-221.6008.13.2211.9477386 Xcode: 14.2/14C18 - /usr/bin/xcodebuild npmPackages: expo: ~48.0.1 => 48.0.1 react: 18.2.0 => 18.2.0 react-native: 0.71.2 => 0.71.2 npmGlobalPackages: eas-cli: 3.5.2 expo-cli: 6.0.8 Expo Workflow: bare

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 24 (9 by maintainers)

Commits related to this issue

Most upvoted comments

expo doctor could help too.

Thanks to everyone who helped to fix this bug. I was able to compile for iOS just by running npm update.

After running yarn upgrade this updated all deps and now it works. Thanks

After some digging, I found out that the problem comes from MATCH_INIT regex in Maps config plugin of @expo/config-plugins:

// Match against `UMModuleRegistryAdapter` (unimodules), and React Native without unimodules (Expo Modules), and SDK +44 React AppDelegate subscriber.
export const MATCH_INIT =
  /(?:(self\.|_)(\w+)\s?=\s?\[\[UMModuleRegistryAdapter alloc\])|(?:RCTBridge\s?\*\s?(\w+)\s?=\s?\[\[RCTBridge alloc\])|(\[self\.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions\])/g;

I made this changes to make it work :

 // Match against `UMModuleRegistryAdapter` (unimodules), and React Native without unimodules (Expo Modules), and SDK +44 React AppDelegate subscriber.
-const MATCH_INIT = /(?:(self\.|_)(\w+)\s?=\s?\[\[UMModuleRegistryAdapter alloc\])|(?:RCTBridge\s?\*\s?(\w+)\s?=\s?\[\[RCTBridge alloc\])|(\[self\.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions\])/g;
+const MATCH_INIT = /-\s*\(BOOL\)\s*application:\s*\(UIApplication\s*\*\s*\)\s*\w+\s+didFinishLaunchingWithOptions:/g;

...
export function addGoogleMapsAppDelegateInit(src: string, apiKey: string): MergeResults {
  ...
  return mergeContents({
    tag: 'react-native-maps-init',
    src,
    newSrc: newSrc.join('\n'),
    anchor: MATCH_INIT,
-    offset: 0,
+    offset: 2,
    comment: '//',
  });
}

I created a patch in my repo in the meantime. You can check and see if it works for you @mariomurrent-softwaresolutions !