react-native-unimodules
react-native-unimodules copied to clipboard
[EXImageLoader] Undefined symbol: _OBJC_CLASS_$_RCTImageLoader
I get this build time error after upgrading react-native-unimodules to 0.8.1
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_RCTImageLoader", referenced from:
objc-class-ref in EXImageLoader.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Changing the contents of node_modules/react-native-unimodules/node_modules/expo-image-loader/ios/EXImageLoader/EXImageLoader.m to
// Copyright 2019-present 650 Industries. All rights reserved.
#import <EXImageLoader/EXImageLoader.h>
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#import <React/RCTImageLoader.h>
#import <React/RCTImageURLLoader.h>
#else
#import "RCTBridgeModule.h"
#import "RCTImageLoader.h"
#import "RCTImageURLLoader.h"
#endif
@interface EXImageLoader ()
@property (weak, nonatomic) RCTBridge *bridge;
@end
@implementation EXImageLoader
UM_REGISTER_MODULE();
+ (NSString *)moduleName
{
return @"EXImageLoader";
}
+ (const NSArray<Protocol *> *)exportedInterfaces
{
return @[@protocol(UMImageLoaderInterface)];
}
- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;
}
- (void)loadImageForURL:(NSURL *)imageURL
completionHandler:(UMImageLoaderCompletionBlock)completionHandler
{
[[self.bridge moduleForName:@"ImageLoader" lazilyLoadIfNecessary:YES] loadImageWithURLRequest:[NSURLRequest requestWithURL:imageURL]
callback:^(NSError *error, UIImage *loadedImage) {
completionHandler(error, loadedImage);
}];
}
@end
seems to fix the build error.
At runtime, images seem to load fine, but ImageBackground from react-native no longer works.
I've also tried what is suggested in this comment from a similar issue: https://github.com/unimodules/react-native-unimodules/issues/97#issuecomment-584062628
to make the contents of EXImageLoader.m:
// Copyright 2019-present 650 Industries. All rights reserved.
#import <EXImageLoader/EXImageLoader.h>
#import <React/RCTImageLoaderProtocol.h>
@interface EXImageLoader ()
@property (weak, nonatomic) RCTBridge *bridge;
@end
@implementation EXImageLoader
UM_REGISTER_MODULE();
+ (NSString *)moduleName
{
return @"EXImageLoader";
}
+ (const NSArray<Protocol *> *)exportedInterfaces
{
return @[@protocol(UMImageLoaderInterface)];
}
- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;
}
- (void)loadImageForURL:(NSURL *)imageURL
completionHandler:(UMImageLoaderCompletionBlock)completionHandler
{
[[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[NSURLRequest requestWithURL:imageURL]
callback:^(NSError *error, UIImage *loadedImage) {
completionHandler(error, loadedImage);
}];
}
@end
With this I also get no build errors, but ImageBackground no longer works.
Same here
Updated today and wondered why my ImageBackgrounds had disappeared.
First: What version were you on before upgrading to 0.8.1?
Also, have you tried switching all of your iOS dependencies to CocoaPods, or at least React Native and anything that depends on React Native? That would mean adding all that stuff to your Podfile, and removing it from project.pbxproj for your app's Xcode project. It's the third solution at https://stackoverflow.com/a/55328241/6792075, which links to https://github.com/facebook/react-native/issues/20492#issuecomment-464343895, and it's a pain. But if a CocoaPods dependency depends on React Native, then React Native needs to be connected via CocoaPods as well. An example Podfile for RN v0.59.x is here; for the latest version (v0.62.x, as of writing), here.
For me, the removal of all those things from project.pbxproj had to be done all at once; I couldn't test it incrementally with, e.g., RCTText by itself. One possible explanation for this requirement is this (quoting from a colleague):
One possibility is something like: we were getting React, as a whole, from the direct references in the Xcode config; and so that version of the built React library had versions of RCTImageView etc. only when those were configured through RCTImage.xcodeproj etc., via direct references to those in our Xcode config.
Whereas the built React library from React.podfile and our Podspec had the RCTImageView that was built due to the RCTImage subspec in our Podfile... but perhaps we just didn't get that one because it had to compete with the libReact.a (or whatever) from our Xcode config. And once we no longer had the latter, we started getting the former instead.
@chrisbobbe I was using 0.7.1 before and RN 0.61.5 and was using CocoaPods in the project from the beginning. With RN 0.62.x this issue no longer exists for me.
My bad, it doesn't work out-of-the-box, I actually have to do the workaround from this comment https://github.com/unimodules/react-native-unimodules/issues/125#issuecomment-603841464 but then at least it works, i.e. ImageBackground also working.
@redpandatronicsuk Any solution for this Undefined symbol: OBJC_CLASS$_RCTImageLoader ?