Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on startup on react-native 0.74 Bridgeless New Architecture #5042

Closed
mHvNG opened this issue Apr 25, 2024 · 21 comments
Closed

Error on startup on react-native 0.74 Bridgeless New Architecture #5042

mHvNG opened this issue Apr 25, 2024 · 21 comments
Labels
bug Something isn't working

Comments

@mHvNG
Copy link

mHvNG commented Apr 25, 2024

Summary

Hi,

While testing the Bridgeless New Architecture of react-native 0.74 I got the following error (NOBRIDGE) ERROR Error: Exception in HostFunction: <unknown> and the following in Xcode SurfaceRegistryBinding::startSurface failed. Global was not installed..

I have ran the entire installation process step by step and the error starts when I add the following to my Podfile:

# React Native Maps dependencies

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

The following screenshot is directly after the bundle was successful.

Simulator Screenshot - iPhone 15 Pro - 2024-04-25 at 14 29 38

If I'm doing something incorrect I wouldn't know where.

Reproducible sample code

Not necessary. It happens before you can even think about implementing a MapView in the App.

Steps to reproduce

Follow the installation instructions on react-native 0.74 with the Bridgeless New Architecture enabled. Once you're at the following step the error will show itself.

# React Native Maps dependencies

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

Expected result

I would like to see the app actually start.

Actual result

Crash on startup

React Native Maps Version

1.14.0

What platforms are you seeing the problem on?

iOS (Google Maps)

React Native Version

0.74.0

What version of Expo are you using?

Not using Expo

Device(s)

iPhone 15 Pro (Simulator)

Additional information

No response

@mHvNG mHvNG added the bug Something isn't working label Apr 25, 2024
@mateki0
Copy link
Collaborator

mateki0 commented Apr 25, 2024

Hi, @mHvNG. Can you show me your AppDelegate.mm? I had the same problem and deleting these booleans helped me

- (BOOL)turboModuleEnabled {
  return true;
}


- (BOOL)fabricEnabled{
  return true;
}

- (BOOL)bridgelessEnabled
{
    return YES;
}

@mHvNG
Copy link
Author

mHvNG commented Apr 25, 2024

@mateki0 Sadly I don't have those booleans... My AppDelegate.mm:

#import "AppDelegate.h"
//#import <GoogleMaps/GoogleMaps.h>

#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//  [GMSServices provideAPIKey:@"API_KEY"]; // add this line using the api key obtained from Google Console
  
  self.moduleName = @"AppName";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  return [self bundleURL];
}

- (NSURL *)bundleURL
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

It's basically the generated AppDelegate.mm file from 0.74 plus the code for adding an API key for Google Maps.

@mHvNG
Copy link
Author

mHvNG commented Apr 25, 2024

@mateki0 I did some further testing to get the cause of the error or at least close enough. When I install react-native-maps with yarn and add the following to the Podfile everything is well:

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

App startup is fine and when using with provider Apple Maps everything works and I can see and interact with the map. However when I add the following to the Podfile I get the error (stated above):

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

You install the following during a npx pod install:

Installing Google-Maps-iOS-Utils (4.2.2)
Installing GoogleMaps (7.4.0)
Installing react-native-google-maps (1.14.0)

My personal conclusion would be that it's an error on the Google Maps side of the library. I hope this helps somewhat.

@mateki0
Copy link
Collaborator

mateki0 commented Apr 26, 2024

Thanks for checking @mHvNG. I see one difference between your and ours podfile. Can you try with this code?

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

I know that it's missing in documentation, but this line pod 'react-native-maps', :path => rn_maps_path was added to our example app 2 months ago so maybe it's needed now and docs should be updated.

Here is whole Podfile of example app with RN 0.74:
https://github.com/TheWidlarzGroup/react-native-maps/blob/chore/bump-example-rn-to-0.74/example/ios/Podfile

@mHvNG
Copy link
Author

mHvNG commented Apr 26, 2024

@mateki0 By removing this:

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

And adding this:

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

I get the following error message:

[!] There are multiple dependencies with different sources for `react-native-maps` in `Podfile`:

- react-native-maps (from `../node_modules/react-native-maps`)
- react-native-maps (from `../..`)

I tried the pod deintegrate and RCT_NEW_ARCH_ENABLED=1 bundle exec pod install again and it still gave the same error. It only seems to take ../node_modules/react-native-maps as an answer to install.

@mateki0
Copy link
Collaborator

mateki0 commented Apr 29, 2024

Sorry for missleading @mHvNG I meant to put there these 3 lines.

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

But now I saw that it doesn't change anything. And you are right, there's a crash. Deleting code from appDelegate helped me because I turned off new arch which you are turning on with pod install command.

Unfortunately I don't know how to fix it or if we are even able to do it. Maybe @brentvatne or @lukmccall are able to help here?

Edit: It's happening on clean rn 0.74 project with turned on new arch, so it's quite easy to reproduce

@mHvNG
Copy link
Author

mHvNG commented Apr 29, 2024

Edit: It's happening on clean rn 0.74 project with turned on new arch, so it's quite easy to reproduce

Yup, it's not difficult to encounter the crash. I saw that version 1.14.0 brought support for the new architecture, however at the moment it's only working without the pod 'react-native-google-maps', :path => rn_maps_path within the Podfile.

It's working fine when I'm working with Apple Maps as the provider. Anyway thanks @mateki0 for trying.

@mrousavy
Copy link

Hey - I'm seeing the same issue with react-native-mmkv, not sure what exactly is causing this.
image

@mHvNG
Copy link
Author

mHvNG commented Apr 29, 2024

@mrousavy The error message itself isn't helpful unfortunately. I'm way too busy developing apps for clients to start and contribute open source libraries for RN at the moment, so my understanding of the migration from old to new architecture isn't up-to-date unfortunately.

However it's weird that one Pod runs perfectly fine, but the Pod: react-native-google-maps crashes instantly while the bundle process finished just fine. It wouldn't shock me if there's something not 100% correct within react-native 0.74 itself.

@mym0404
Copy link

mym0404 commented Apr 30, 2024

Well, I suffered same in 0.74 Bridgeless Android. It means it is just not a issue in iOS only.

But in my project(app) it doesn't use react-native-maps but mmkv V2 is used(IDK even it is related with MMKV). I need to investigate it further.

Logcat (android)

09:23:01.373  W  ReactHost{0}.getOrCreateDestroyTask()
09:23:01.373  W  ReactHost{0}.getOrCreateDestroyTask(): handleHostException(message = "SurfaceRegistryBinding::stopSurface failed. Global was not installed.")
09:23:01.374  W  ReactHost{0}.handleHostException(message = "SurfaceRegistryBinding::stopSurface failed. Global was not installed.")
09:23:01.374  E  Exception in native call
                 java.lang.RuntimeException: SurfaceRegistryBinding::stopSurface failed. Global was not installed.
                 	at com.facebook.jni.NativeRunnable.run(Native Method)
                 	at android.os.Handler.handleCallback(Handler.java:942)
                 	at android.os.Handler.dispatchMessage(Handler.java:99)
                 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
                 	at android.os.Looper.loopOnce(Looper.java:201)
                 	at android.os.Looper.loop(Looper.java:288)
                 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233)
                 	at java.lang.Thread.run(Thread.java:1012)
09:23:01.374  W  ReactHost{0}.getOrCreateDestroyTask()
09:23:01.374  W  ReactHost{0}.getOrCreateDestroyTask(): handleHostException(message = "SurfaceRegistryBinding::stopSurface failed. Global was not installed.")
09:23:01.444  W  Expecting binder but got null!
09:23:01.449  E  Surface [31] was stopped on SurfaceMountingManager.
09:23:01.454  E  Surface [11] was stopped on SurfaceMountingManager.

@cipolleschi
Copy link

cipolleschi commented Apr 30, 2024

I found the issue and it looks like it is this line.

By returning an empty string instead of [GMSService openSourceLicenseInfo], the app loads successfully.
The problem is that [GMSService openSourceLicenseInfo] is broken... I tried to call it in isolation and it crashes.

@cipolleschi
Copy link

Update: it crashes because with Bridgeless mode this function is called in background. The exception that is raised is

[AIRGoogleMapManager constantsToExport] threw and exception: The API method must be called from the main thread

So we need to fix it in React Native. I don't have a solution right away, but the fix will come.

@mym0404
Copy link

mym0404 commented Apr 30, 2024

Update: it crashes because with Bridgeless mode this function is called in background. The exception that is raised is

[AIRGoogleMapManager constantsToExport] threw and exception: The API method must be called from the main thread

So we need to fix it in React Native. I don't have a solution right away, but the fix will come.

Can you share how to trace log in this issue? It will be a great help for finding our common issues.

cipolleschi added a commit to cipolleschi/react-native that referenced this issue Apr 30, 2024
Summary:
We [received an issue](react-native-maps/react-native-maps#5042) in OSS where a ViewManager was configured to be initialized on the main queue, but it wasn't.
This was creating a soft crash and showing a RedBox to the user.
The library was going through the Interop Layer.

This change makes sure that, if the ViewManager is configured to be setup in the main queue, we retrieve the constants from the Main Queue

## Changelog
[iOS][Fixed] - Extract the constants from ViewManagers in the UI Thread if needed.

Differential Revision: D56762253
@cipolleschi
Copy link

@mym0404 sure!

  1. I enabled a feature of Xcode breakpoints which is Exception Breakpoints
Screenshot_2024-04-30_at_14 36 05
  1. I run the app and see that the constantsToExport was raising an exception.
    At this point, I had few ways to go:
  • I tried to replace the [GMSServices openSourceLicenseInfo]; line with an empty string => no crashes and no redboxes
  • I wrapped the [GMSService openSourceLicenseInfo]; in a try-catch block to see the exception
@try {
    license = [GMSServices openSourceLicenseInfo];
  } @catch (NSException *ex) {
    NSLog(@"[GMSServices openSourceLicenseInfo] threw and exception: %@",  ex);
  }

@matt-dalton
Copy link

FWIW I am getting this and don't use react-native-maps. I do use mmkv, and have upgraded to the 3.0.0-beta.4 release to remain compliant with 0.74.

facebook-github-bot pushed a commit to facebook/react-native that referenced this issue May 1, 2024
Summary:
We [received an issue](react-native-maps/react-native-maps#5042) in OSS where a ViewManager was configured to be initialized on the main queue, but it wasn't.
This was creating a soft crash and showing a RedBox to the user.
The library was going through the Interop Layer.

This change makes sure that, if the ViewManager is configured to be setup in the main queue, we retrieve the constants from the Main Queue

## Changelog
[iOS][Fixed] - Extract the constants from ViewManagers in the UI Thread if needed.

Reviewed By: sammy-SC

Differential Revision: D56762253

fbshipit-source-id: ca807b34d6e61418da9fd6a639a05f3394879f7c
@cipolleschi
Copy link

@matt-dalton @mrousavy let's move the MMKV discussion to the MMKV repo, so we can close this issue for maps.

cipolleschi added a commit to facebook/react-native that referenced this issue May 1, 2024
Summary:
We [received an issue](react-native-maps/react-native-maps#5042) in OSS where a ViewManager was configured to be initialized on the main queue, but it wasn't.
This was creating a soft crash and showing a RedBox to the user.
The library was going through the Interop Layer.

This change makes sure that, if the ViewManager is configured to be setup in the main queue, we retrieve the constants from the Main Queue

## Changelog
[iOS][Fixed] - Extract the constants from ViewManagers in the UI Thread if needed.

Reviewed By: sammy-SC

Differential Revision: D56762253

fbshipit-source-id: ca807b34d6e61418da9fd6a639a05f3394879f7c
kosmydel pushed a commit to kosmydel/react-native that referenced this issue May 6, 2024
Summary:
We [received an issue](react-native-maps/react-native-maps#5042) in OSS where a ViewManager was configured to be initialized on the main queue, but it wasn't.
This was creating a soft crash and showing a RedBox to the user.
The library was going through the Interop Layer.

This change makes sure that, if the ViewManager is configured to be setup in the main queue, we retrieve the constants from the Main Queue

## Changelog
[iOS][Fixed] - Extract the constants from ViewManagers in the UI Thread if needed.

Reviewed By: sammy-SC

Differential Revision: D56762253

fbshipit-source-id: ca807b34d6e61418da9fd6a639a05f3394879f7c
@mateki0
Copy link
Collaborator

mateki0 commented May 7, 2024

@mHvNG It works fine for me on 0.74.1. Can you confirm that so we can close the issue?

@rodrigodiasf1984
Copy link

rodrigodiasf1984 commented May 7, 2024

i managed to install the pods with these modifications at the PodFile on the react-native 0.74.1 and "react-native-maps": "^1.15.1",
rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => rn_maps_path pod 'react-native-maps', :path => rn_maps_path

but the build crashes, any idea how to solve it?
#include <react/debug/react_native_assert.h> 'react/debug/react_native_assert.h' file not found
image

@mateki0
Copy link
Collaborator

mateki0 commented May 8, 2024

@rodrigodiasf1984 there was similar issue in the past opened in react-native repository, maybe you will find something helpful there. If not please open separate issue with your package.json and whole Podfile because I don't think it's connected with this one.
facebook/react-native#38283

@rodrigodiasf1984
Copy link

@rodrigodiasf1984 there was similar issue in the past opened in react-native repository, maybe you will find something helpful there. If not please open separate issue with your package.json and whole Podfile because I don't think it's connected with this one. facebook/react-native#38283

I saw this issue before, but the error i got ins't the same, their talking about RunLoopObserver my error is different, i will open another issue

@mHvNG
Copy link
Author

mHvNG commented May 8, 2024

@mHvNG It works fine for me on 0.74.1. Can you confirm that so we can close the issue?

@mateki0 I'll check when I get home from work. I'll close the issue when all is working.

@mHvNG mHvNG closed this as completed May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants