tradle / rn-nodeify

hack to allow react-native projects to use node core modules, and npm modules that use them
MIT License
618 stars 112 forks source link

iOS Build is failing (duplicate symbols for architecture x86_64) #114

Open jonathanschad opened 2 years ago

jonathanschad commented 2 years ago

This issue should serve as a starting point for others who have the same problem. I hope I can save you from a lot of headache. Original Issue: https://github.com/Rapsssito/react-native-tcp-socket/issues/61#issuecomment-653881488

Steps to reproduce

The issue appears if you try to compile a react native project for iOS, which uses rn-nodefiy. To be more specific the cause of the problem seems to come from react-native-tcp and react-native-udp.

It seems that it also does not matter if you use a new M1 Mac or an older Intel based Mac. Also it does not matter if you use npm or yarn

  1. Create a new react native project npx react-native init AwesomeTSProject --template react-native-template-typescript

At this point your iOS version should still build correctly.

  1. install rn-nodeify. npx rn-nodeify --install --hack

  2. install pods cd ios & pod install

  3. Try to build the project for iOS again npm run ios

Your build will fail with the message ld: {number} duplicate symbols for architecture x86_64

How to solve it

Credit to @Jiope

  1. Go to xcode
  2. into project navigator, click on Pods folder
  3. then select TcpSockets in targets
  4. Go to Build Phases > Compile sources
  5. Here remove reference to CocoaAsyncSocket (this should be the first entry in the list)

in this case you also need to do the same for react-native-udp

It seems like you need to redo this procedure every time you add new dependencies to your project

DedicatedDev commented 2 years ago

Credit to @Jiope

Go to xcode into project navigator, click on Pods folder then select TcpSockets in targets Go to Build Phases > Compile sources Here remove reference to CocoaAsyncSocket (this should be the first entry in the list) in this case you also need to do the same for react-native-udp

this is correct solution.

Florent75 commented 2 years ago

Hi there,

I just tried to install this package and I do have the same issue.

Here is part of the error logs : duplicate symbol '_OBJCIVAR$_GCDAsyncUdpSocket.cachedLocalPort4' in: /Users/florent/Library/Developer/Xcode/DerivedData/Hermes-dxhzvnkbnyrabocodwsqwfpatpub/Build/Products/Debug-iphonesimulator/CocoaAsyncSocket/libCocoaAsyncSocket.a(GCDAsyncUdpSocket.o) /Users/florent/Desktop/Bocoloco/git_florent_reactnative/HermesNative/florent_reactnative_hermes/node_modules/react-native-thermal-receipt-printer/ios/PrinterSDK/libPrinterSDK.a(GCDAsyncUdpSocket.o) duplicate symbol '_OBJCIVAR$_GCDAsyncUdpSocket.cachedLocalAddress4' in: /Users/florent/Library/Developer/Xcode/DerivedData/Hermes-dxhzvnkbnyrabocodwsqwfpatpub/Build/Products/Debug-iphonesimulator/CocoaAsyncSocket/libCocoaAsyncSocket.a(GCDAsyncUdpSocket.o) /Users/florent/Desktop/Bocoloco/git_florent_reactnative/HermesNative/florent_reactnative_hermes/node_modules/react-native-thermal-receipt-printer/ios/PrinterSDK/libPrinterSDK.a(GCDAsyncUdpSocket.o) duplicate symbol '_OBJCIVAR$_GCDAsyncUdpSocket.writeStream4' in: /Users/florent/Library/Developer/Xcode/DerivedData/Hermes-dxhzvnkbnyrabocodwsqwfpatpub/Build/Products/Debug-iphonesimulator/CocoaAsyncSocket/libCocoaAsyncSocket.a(GCDAsyncUdpSocket.o) /Users/florent/Desktop/Bocoloco/git_florent_reactnative/HermesNative/florent_reactnative_hermes/node_modules/react-native-thermal-receipt-printer/ios/PrinterSDK/libPrinterSDK.a(GCDAsyncUdpSocket.o) duplicate symbol '_OBJCIVAR$_GCDAsyncUdpSocket.readStream4' in: /Users/florent/Library/Developer/Xcode/DerivedData/Hermes-dxhzvnkbnyrabocodwsqwfpatpub/Build/Products/Debug-iphonesimulator/CocoaAsyncSocket/libCocoaAsyncSocket.a(GCDAsyncUdpSocket.o) /Users/florent/Desktop/Bocoloco/git_florent_reactnative/HermesNative/florent_reactnative_hermes/node_modules/react-native-thermal-receipt-printer/ios/PrinterSDK/libPrinterSDK.a(GCDAsyncUdpSocket.o) ld: 137 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

It seems to have some kind if conflict with the react-native-thermal-receipt-printer module.

When I check on the Pods targe / react-native-tcp-sockets / compile sources , there is nothing like CocoaAsyncSocket, but I can found it in the dependency.

Do you have any clues on how o fix it ?

Regards

Rc85 commented 2 years ago

@Florent75 There is a troubleshoot section in the docs about removing Flipper. If you are still having that issue after commenting out all the flipper reference in your Podfile and AppDelegate.m, then you mostly likely still have Flipper in your Pods folder. Run pod deintegrate and pod install.

chachaxw commented 2 years ago

Credit to @Jiope

Go to xcode into project navigator, click on Pods folder then select TcpSockets in targets Go to Build Phases > Compile sources Here remove reference to CocoaAsyncSocket (this should be the first entry in the list) in this case you also need to do the same for react-native-udp

this is correct solution.

It works for me, amazing🤩

nriccar commented 1 year ago

Any way of doing this promatically from podfile or a patch-package so that we don't have to manually remove CocoaAsyncSocket after each pod install?

Kailash23 commented 5 months ago

Any way of doing this promatically from podfile or a patch-package so that we don't have to manually remove CocoaAsyncSocket after each pod install?

Facing the same issue CocoaAsyncSocket compile source keep adding again after pod install