Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating react native and getting Subclasses must implement a valid getBundleURL method

I've recently updated react native to the latest version (as painful as it is), and I'm getting this error. The code compiles fine but as soon as the app runs I receive this.

'RCTAppDelegate::bundleURL not implemented', reason: 'Subclasses must implement a valid getBundleURL method'

Any ideas? Thanks!

like image 324
zak Avatar asked Sep 08 '26 11:09

zak


1 Answers

I've been through this as well and solved this issue by dividing the sourceURLForBridge method inside the AppDelegate.m into two functions:

If you're using expo it should be:

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

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

If you're using plain cli it should be:

- (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
}

This is also how you're AppDelegate looks like, if you create a plain new project - which is always a good reference after updating an old one.

like image 134
Chris Avatar answered Sep 13 '26 04:09

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!