thekevinbrown/react-native-schemes-manager

ld: 843 duplicate symbols for architecture x86_64 error

gavin-gmlab opened this issue · 10 comments

I'm cracking my head over getting schemes to work on my project. I use Cocoapods for some libraries and regular npm install for others.

My pod file:
target 'project' do
pod 'RSKImageCropper'
pod 'QBImagePickerController'
pod 'Fabric'
pod 'Crashlytics'

target 'projectTests' do
  inherit! :search_paths
  # Pods for testing
end

end

My xcodeSchemes:
"xcodeSchemes": {
"Debug": ["xDebug"],
"Release": ["xRelease", "xStaging", "Staging"],
"projectDirectory": "ios",
"settings": {
}
},

Steps to reproduce the behavior

Make the base project/scheme work first, then execute npm run postinstall, then try to run in another scheme.

Build error in xcode:

duplicate symbol _OBJC_IVAR_$_RCTCxxMethod._method in:
    /Users/x/ios/Build/Products/xDebug-iphonesimulator/libReact.a(RCTCxxMethod.o)
    /Users/x/ios/Build/Products/Debug-iphonesimulator/libReact.a(RCTCxxMethod.o)
duplicate symbol _OBJC_CLASS_$_RCTCxxMethod in:
    /Users/x/ios/Build/Products/xDebug-iphonesimulator/libReact.a(RCTCxxMethod.o)
    /Users/x/ios/Build/Products/Debug-iphonesimulator/libReact.a(RCTCxxMethod.o)
....

    /Users/x/ios/Build/Products/Debug-iphonesimulator/libReact.a(RCTModalManager.o)
duplicate symbol _OBJC_METACLASS_$_RCTModalManager in:
    /Users/x/ios/Build/Products/xDebug-iphonesimulator/libReact.a(RCTModalManager.o)
    /Users/x/ios/Build/Products/Debug-iphonesimulator/libReact.a(RCTModalManager.o)
ld: 843 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

When I try to run from a scheme in the release configuration (xStaging), I get a slightly different error:
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_RCTReconnectingWebSocket", referenced from: objc-class-ref in libReact.a(RCTPackagerConnection.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Expected behavior

Should be able to run/build in the various schemes.

Actual behavior

What happens if you remove react-native-schemes-manager by following these steps?

Basically that looks like a linker error, which indicates a problem in getting all your libraries in and is likely not related to your schemes directly, and would be unrelated to this library, but I've seen Xcode do weird things, so would definitely rather check and be sure first!

Reverting back to the pre-schemes setup always works. I've tried this so many times to get it to work. It's either duplicates or not found... Sooo frustrating(nothing against this schemes manager, but Xcode in general)

Any chance you could give me a repro project so I can play around on my side and see if I can figure it out?

Hmm, that would be a bit hard @blargity Quite a lot of stuff to strip out.

If there was somewhere that explains what is going on during a build so that I can even do this manually, it would help

Alrighty, in that case I'm afraid there's not much I can do to help. It's very unlikely that this is being caused by the library because mostly what it does is copy existing build configs around in the projects in your node_modules directory, but I'd be happy to be shown wrong, just need to see some code that causes it.

Have you tried removing schemes manager but leaving the schemes themselves set up? I suspect it's caused by your actual scheme configuration, rather than something the library is doing. Other than that, I'm afraid I don't have much to go on.

All that's going on during a build is exactly what Xcode does out of the box. This project only changes things when it's run, and the running is configured (if you did what's in the readme) to happen on postinstall (triggered by yarn or npm, nothing triggered by Xcode). We also swap a script in instead of the one packaged by React Native, but the only actual change there is changing the condition on an if statement to recognise more build configurations as Debug.

So, long story short, we're not doing anything at all on build. We configure the files on postinstall, and then Xcode does its thing.

If there's something I can have a look at let me know.

Appreciate your offer to help @blargity. Understand this library is just activated at post install. The problem definitely has something to do with the paths within Xcode, but I'm not a Xcode expert. The default Debug scheme works, but the others do not.

I found that this link https://stackoverflow.com/questions/39626055/created-new-xcode-configuration-and-scheme-linker-is-suddenly-failing helped with getting the schemes copied from Debug working, but the schemes copied from Release is still failing due to library not found.

The most problematic library I have is react-native-image-crop-picker, where if you see the current install instructions and pod file, requires the node modules to be installed first, then after that running pod install. Not sure if that is catered to by the post install, because it would seem that postinstall wouldn't work properly without all the pods being there.

A little update: Found out that just by changing the configuration in a working scheme from release to say Staging will already cause the build to fail..... Have yet to figure this out.

I now have a stripped out version of the project where the default debug and release configs work, but all other configs/schemes don't, if anyone is still able to help troubleshoot.

Managed to resolve the problem.

Steps taken:

  1. Reconstruct the project from scratch
  2. Include react-native-schemes-manager in the process.
  3. In custom schemes, ensure that the React build target is present in Edit Scheme->build. It was not always there. If not, add it by clicking on the + and moving the React target above your project target.

I'm glad to hear you were able to solve it, sorry I wasn't more help!