Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 292 forks source link

Build fails with Apple M1 chip when using `arm64` on iOS simulator #226

Closed andreialecu closed 3 years ago

andreialecu commented 3 years ago

This is on a Mac Mini using the new M1 Apple Silicon chip.

It seems that the pods fail to compile when the arm64 architecture is enabled, which is by default. I am not sure why this happens, but it seems to be related to swift.

If I add arm64 to Excluded Architectures the build completes properly, but the entire app gets arm64 disabled and it performs poorly on the simulator.

These warnings appear:

ld: warning: Could not find or use auto-linked library 'swiftCoreLocation'
ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find or use auto-linked library 'swiftDarwin'
ld: warning: Could not find or use auto-linked library 'swiftUIKit'
ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
ld: warning: Could not find or use auto-linked library 'swiftCore'
ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
ld: warning: Could not find or use auto-linked library 'swiftDispatch'
ld: warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
ld: warning: Could not find or use auto-linked library 'swiftFoundation'
ld: warning: Could not find or use auto-linked library 'swiftMetal'

And afterwards it lists 100+ errors similar to:

Undefined symbols for architecture arm64:
  "method descriptor for Foundation._BridgedStoredNSError.init(_nsError: __C.NSError) -> A", referenced from:
      l_got.$s10Foundation21_BridgedStoredNSErrorP8_nsErrorxSo0D0C_tcfCTq in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "base conformance descriptor for Foundation._BridgedStoredNSError: Foundation.CustomNSError", referenced from:
      l_got.$s10Foundation21_BridgedStoredNSErrorPAA06CustomD0Tb in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "associated type descriptor for Foundation._ErrorCodeProtocol._ErrorType", referenced from:
      l_got.$s10_ErrorType10Foundation01_A12CodeProtocolPTl in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "associated conformance descriptor for Foundation._BridgedStoredNSError.Foundation._BridgedStoredNSError.Code: Foundation._ErrorCodeProtocol", referenced from:
      l_got.$s10Foundation21_BridgedStoredNSErrorP4CodeAC_AA06_ErrorE8ProtocolTn in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "base conformance descriptor for Foundation._ErrorCodeProtocol: Swift.Equatable", referenced from:
      l_got.$s10Foundation18_ErrorCodeProtocolPSQTb in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "method descriptor for static Foundation.CustomNSError.errorDomain.getter : Swift.String", referenced from:
      l_got.$s10Foundation13CustomNSErrorP11errorDomainSSvgZTq in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "base conformance descriptor for Foundation.CustomNSError: Swift.Error", referenced from:
      l_got.$s10Foundation13CustomNSErrorPs5ErrorTb in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "protocol descriptor for Foundation.CustomNSError", referenced from:
      l_got.$s10Foundation13CustomNSErrorMp in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "method descriptor for Foundation._ObjectiveCBridgeableError.init(_bridgedNSError: __shared __C.NSError) -> A?", referenced from:
      l_got.$s10Foundation26_ObjectiveCBridgeableErrorP15_bridgedNSErrorxSgSo0F0Ch_tcfCTq in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "base conformance descriptor for Foundation._BridgedStoredNSError: Foundation._ObjectiveCBridgeableError", referenced from:
      l_got.$s10Foundation21_BridgedStoredNSErrorPAA26_ObjectiveCBridgeableErrorTb in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "protocol descriptor for Foundation._ObjectiveCBridgeableError", referenced from:
      l_got.$s10Foundation26_ObjectiveCBridgeableErrorMp in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "method descriptor for Swift.Error._getEmbeddedNSError() -> Swift.AnyObject?", referenced from:
      l_got.$ss5ErrorP19_getEmbeddedNSErroryXlSgyFTq in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "method descriptor for Swift.Error._code.getter : Swift.Int", referenced from:
      l_got.$ss5ErrorP5_codeSivgTq in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "method descriptor for Swift.RawRepresentable.rawValue.getter : A.RawValue", referenced from:
      l_got.$sSY8rawValue03RawB0QzvgTq in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "associated type descriptor for Swift.RawRepresentable.RawValue", referenced from:
      l_got.$s8RawValueSYTl in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "base conformance descriptor for Foundation._ObjectiveCBridgeableError: Swift.Error", referenced from:
      l_got.$s10Foundation26_ObjectiveCBridgeableErrorPs0D0Tb in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "method descriptor for Swift.Hashable._rawHashValue(seed: Swift.Int) -> Swift.Int", referenced from:
      l_got.$sSH13_rawHashValue4seedS2i_tFTq in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "method descriptor for Swift.Hashable.hashValue.getter : Swift.Int", referenced from:
      l_got.$sSH9hashValueSivgTq in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "protocol descriptor for Swift.Equatable", referenced from:
      l_got.$sSQMp in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "value witness table for Builtin.Int32", referenced from:
      full type metadata for __C.CLAuthorizationStatus in libreact-native-geolocation-service.a(RNFusedLocation.o)
  "_swift_deallocObject", referenced from:
      l_objectdestroy in libreact-native-geolocation-service.a(RNFusedLocation.o)
      l_objectdestroy.2 in libreact-native-geolocation-service.a(RNFusedLocation.o)
      l_objectdestroy.5 in libreact-native-geolocation-service.a(RNFusedLocation.o)
      l_objectdestroy.8 in libreact-native-geolocation-service.a(RNFusedLocation.o)
      l_objectdestroy.11 in libreact-native-geolocation-service.a(RNFusedLocation.o)
      l_objectdestroy.15 in libreact-native-geolocation-service.a(RNFusedLocation.o)
      l_objectdestroy.18 in libreact-native-geolocation-service.a(RNFusedLocation.o)

Any suggestions for things to try would be appreciated!

andreialecu commented 3 years ago

I was able to get it to build by adding an empty swift file to the project so that a bridging header is created.

And more importantly removing this:

                LIBRARY_SEARCH_PATHS = (
                    "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
                    "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
                    "\"$(inherited)\"",
                );

From project.pbxproj for both debug and release. I haven't tested for side effects, but now it builds and runs in arm64 mode on the simulator.

I'm not sure why this is required, might be an issue with React Native.

celciusjj commented 3 years ago

Another solution? I have the same problem.

TylerEich commented 3 years ago

I don't know of the side effects either, but @andreialecu's suggestion helped me to get the project running in the simulator. It would run fine on a physical device, but it would fail with 100 errors every time I tried to do a simulator run.

svnm commented 3 years ago

For me it was this change

https://github.com/Agontuk/react-native-geolocation-service/commit/2502ffd082b610d78fd32ca987e256468ad90e4b

So fixing this and patching the package fixed it for me

In node_modules/react-native-geolocation-service Open react-native-geolocation-service.podspec

Change s.dependency "React" back to s.dependency "React-Core"

Follow the steps to add a patch https://www.npmjs.com/package/patch-package

All worked fine after that after yarn install, pod install

Himatheja commented 2 years ago

For me it was this change

2502ffd

So fixing this and patching the package fixed it for me

In node_modules/react-native-geolocation-service Open react-native-geolocation-service.podspec

Change s.dependency "React" back to s.dependency "React-Core"

Follow the steps to add a patch https://www.npmjs.com/package/patch-package

All worked fine after that after yarn install, pod install

Awesome. This worked for me. Can you please explain why do we need to do this ? I'm curious...!!! Thanks in advance.