iosxcodereact-nativebuild-errorapple-m1

Build is failing for older projects for React-Native iOS XCode Version 12.5


It is very new to me see this problem which started happening recently. Previously my app used to work fine on the iOS simulator by running this command react-native run-ios. Now I have done a lot of research and made my app run via XCode. But somehow the metro bundler is not linked when the app runs via XCode.

I tried running the app via react-native run-ios and every time I am seeing this error. It is too big to copy paste every error here, but here are some of them:

Undefined symbols for architecture x86_64:
  "Swift._ArrayBuffer._copyContents(initializing: Swift.UnsafeMutableBufferPointer<A>) -> (Swift.IndexingIterator<Swift._ArrayBuffer<A>>, Swift.Int)", referenced from:
      generic specialization <serialized, Swift._ArrayBuffer<Swift.Int8>> of Swift._copyCollectionToContiguousArray<A where A: Swift.Collection>(A) -> Swift.ContiguousArray<A.Element> in libMixpanel-swift.a(AutomaticProperties.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


** BUILD FAILED **


The following build commands failed:
        Ld /Users/careerlabsdev/Library/Developer/Xcode/DerivedData/CareerLabs_Elev8-gxcfanteiuxazegkgwkjkrjxbdmw/Build/Products/Debug-iphonesimulator/CareerLabs.app/CareerLabs normal
(1 failure)

I have done a lot of things to make it to work. The only success I got here is, while running the command react-native run-ios, it opens up the metro bundler server. After that it fails with giving a 1000 lines of error. I picked the error which had some cream part. Some key words to pick from the error:

What I did is as follows:

  1. Deleting node_modules, Pods. Cleaning the build from XCode. Running npm install and then cd ios && pod install and then ran the command react-native run-ios
  2. Deleting Pods, Podfile.lock. Did pod install and then in the root react-native run-ios
  3. Doing these:
rm -rf ~/Library/Caches/CocoaPods
rm -rf Pods
rm -rf ~/Library/Developer/Xcode/DerivedData/*
pod deintegrate
pod setup
pod install
cd ..
react-native run-ios
  1. Restarted the system, and ran the command again react-native run-ios
  2. Added arm64 in the Excluded Architecture from XCode. Please note, this enabled me to build and run the app successfully on XCode. But it doesn't get attached to the metro bundler server. Looks like it runs the release mode only.
  3. Updated my package react-native-gesture-handler to the latest one which is 1.10.3, to see if that removes my problem. But no luck.

My Podfile look like this:

  platform :ios, '10.0'

  use_flipper!({'Flipper' => '0.81.0'})
  post_install do |installer|
    flipper_post_install(installer)
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      end
    end
  end

I am out of options now, and waiting for some insight to be given. It is indeed frustrating to see an error on something which never created a problem. I am using Apple M1 Chip Macbook.

Update V1.0

Update V2.0

I have found some significant places where the developers are complaining about the same. XCode has forced updated my version to 12.5, without my notice. And now XCode is creating a problem with RN Older projects. Here are the supportive links for the same:

I hope this may give some insight to the developers who are confused like me. Please take a look, and looks like Facebook is fixing it, but don't know when. Have to keep an eye on it :/


Solution

  • The one hacky thing which I did to make my app run again like before, is to downgrade the XCode Version to the previous stable one, that is Version 12.4. I knew about the problem later, because, XCode force updated my version which started behaving weird with my already existing project. So the only viable option I saw is to downgrade the version to the previous one, and everything worked like before.

    Please Note: This issue exists majorly with Apple M1 along with XCode v12.5 and BigSur OS. So go ahead keeping these things in your mind.

    For this, I had to do these things: