Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build release version for iOS with the new architecture #33764

Closed
wood1986 opened this issue May 5, 2022 · 19 comments
Closed

Unable to build release version for iOS with the new architecture #33764

wood1986 opened this issue May 5, 2022 · 19 comments
Labels
Impact: Errors During Build Platform: iOS iOS applications. Priority: High Resolution: Fixed A PR that fixes this issue has been merged. Tech: React Native Core Issue related to the Core of React Native Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@wood1986
Copy link
Contributor

wood1986 commented May 5, 2022

Description

I am unable to build release version for iOS with the new architecture. But I can build the debug version.

Here is build error

Undefined symbols for architecture x86_64:
  "folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::deferredReaders", referenced from:
      void folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::applyDeferredReaders<folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::WaitForever>(unsigned int&, folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::WaitForever&) in AppDelegate.o
      void folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::applyDeferredReaders<folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::WaitForever>(unsigned int&, folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::WaitForever&, unsigned int) in AppDelegate.o
  "folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::unlock()", referenced from:
      std::__1::unique_lock<folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false> >::~unique_lock() in AppDelegate.o
  "folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::~SharedMutexImpl()", referenced from:
      std::__1::__shared_ptr_emplace<facebook::react::ContextContainer const, std::__1::allocator<facebook::react::ContextContainer const> >::__on_zero_shared() in AppDelegate.o
ld: symbol(s) not found for architecture x86_64

Version

0.68.1

Output of npx react-native info

info Fetching system and libraries information...
System:
    OS: macOS 12.3.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 749.82 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.0.0 - ~/.nvm/versions/node/v18.0.0/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v18.0.0/bin/yarn
    npm: 8.6.0 - ~/.nvm/versions/node/v18.0.0/bin/npm
    Watchman: 2022.03.21.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /Users/wood/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8309675
    Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.15 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.68.1 => 0.68.1
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. npx react-native init AwesomeTSProject --template react-native-template-typescript
  2. Run RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
  3. npx react-native run-ios --configuration Release

Snack, code example, screenshot, or link to a repository

Undefined symbols for architecture x86_64:
  "folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::deferredReaders", referenced from:
      void folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::applyDeferredReaders<folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::WaitForever>(unsigned int&, folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::WaitForever&) in AppDelegate.o
      void folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::applyDeferredReaders<folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::WaitForever>(unsigned int&, folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::WaitForever&, unsigned int) in AppDelegate.o
  "folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::unlock()", referenced from:
      std::__1::unique_lock<folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false> >::~unique_lock() in AppDelegate.o
  "folly::SharedMutexImpl<false, void, std::__1::atomic, false, false, false>::~SharedMutexImpl()", referenced from:
      std::__1::__shared_ptr_emplace<facebook::react::ContextContainer const, std::__1::allocator<facebook::react::ContextContainer const> >::__on_zero_shared() in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
@react-native-bot react-native-bot added the Platform: iOS iOS applications. label May 5, 2022
@cortinico cortinico added the Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) label May 5, 2022
@tj-mc
Copy link

tj-mc commented May 6, 2022

Followed steps but unable to reproduce on M1 Pro

@wood1986
Copy link
Contributor Author

wood1986 commented May 6, 2022

I missed the step. But did you RCT_NEW_ARCH_ENABLED=1 bundle exec pod install?

@Arkkeeper
Copy link
Contributor

This issue persists both in RN 0.68.x and 0.69 when trying to build release version or to make an archive.

I'm facing it when building for MacCatalyst on M1.

You may add these lines to the end of post_install do |installer| as a temporary solution:

rm -f Pods/Flipper-Folly/folly/SharedMutex.cpp Pods/Flipper-Folly/folly/SharedMutex.h
cp Pods/RCT-Folly/folly/SharedMutex.cpp Pods/Flipper-Folly/folly/
cp Pods/RCT-Folly/folly/SharedMutex.h Pods/Flipper-Folly/folly/

@fabOnReact
Copy link
Contributor

fabOnReact commented May 15, 2022

@cipolleschi
Copy link
Contributor

Hi @wood1986, thanks for the issue. Is the issue solved with the #33167 linked by @fabriziobertoglio1987 or is it still there?

@cortinico
Copy link
Contributor

Hi @wood1986, thanks for the issue. Is the issue solved with the #33167 linked by @fabriziobertoglio1987 or is it still there?

@cipolleschi Nope I don't think the linked PR is relevant here. Such PR was fixing a build failure on Android, while the user is reporting an issue on iOS

@fabOnReact
Copy link
Contributor

sorry. I don't know the solution to this issue. I just included links to relevant conversations, which would help me find a solution. What I did find out is the following:

Similar issue was experienced in the past. The symbol error was previously caused by folly depending on libc++abi
8b6d7fd

seems that https://stackoverflow.com/a/33686591/7295772 different environment use different libraries

https://gcc.gnu.org/onlinedocs/gcc-11.3.0/libstdc++/api/a00176_source.html
8b6d7fd#diff-5de3520951eb222bc3b5b734cc1003e84a53fb42220159fedc58768bda2e2cf3R75

this are the folly releases https://github.com/facebook/folly/releases. I did not find anything relevant in the new releases.

@Arkkeeper understand this issue and he tested this solution

rm -f Pods/Flipper-Folly/folly/SharedMutex.cpp Pods/Flipper-Folly/folly/SharedMutex.h
cp Pods/RCT-Folly/folly/SharedMutex.cpp Pods/Flipper-Folly/folly/
cp Pods/RCT-Folly/folly/SharedMutex.h Pods/Flipper-Folly/folly/

so seems that the issue is caused by the Flipper-Folly SharedMutex , while it works with RCT-Folly SharedMutex

this are the configs for folly futures in Flipper-Folly
https://github.com/facebook/flipper/blob/0f038218f893d86e91714cd91eed8e37d756386c/iOS/Podspecs/Flipper-Folly.podspec#L74

this are the configs for folly-futures in RCT-Folly
https://github.com/facebook/react-native/blob/main/third-party-podspecs/RCT-Folly.podspec#L106-L148

I'm not sure that this is connected to futures
The above PR fixed the issue in folly futures, https://github.com/facebook/folly/blob/b72a70a35ada45ac286eb60028c0ecf5f6725665/folly/SharedMutex.h#L554-L571 as the undefined reference was unlock_shared

This is an explanation of unlock_shared, deferredReaders seems to be an array of readers used to access data

https://github.com/facebook/folly/blob/69b6f947ea9aeb73235ccabf235a6804e0f54946/folly/SharedMutex.h#L128-L161

in this case the undefined symbol is folly::SharedMutexImpl<..>::deferredReaders

It's 22:35 here and I have to go to sleep. Sorry for my incomplete message. 🙏
I'll come back to this post in the future. Thanks.

@wood1986
Copy link
Contributor Author

I have a question for you guys.

Doing this does not make sense

rm -f Pods/Flipper-Folly/folly/SharedMutex.cpp Pods/Flipper-Folly/folly/SharedMutex.h
cp Pods/RCT-Folly/folly/SharedMutex.cpp Pods/Flipper-Folly/folly/
cp Pods/RCT-Folly/folly/SharedMutex.h Pods/Flipper-Folly/folly/

If I comment out use_flipper!() in the Podfile, I can build release successfully. Is building release without flipper the best practice?

@fortmarek
Copy link
Contributor

Is building release without flipper the best practice?

Flipper should never be in the release app but it should be done via compilation flags instead of commenting out Podfile. Check out the template app which already does a good job of stripping out Flipper when not in DEBUG.

@f-meloni
Copy link
Contributor

Is building release without flipper the best practice?

Flipper should never be in the release app but it should be done via compilation flags instead of commenting out Podfile. Check out the template app which already does a good job of stripping out Flipper when not in DEBUG.

👍🏻 I totally agree.
I've tried to simplify the Flipper configuration, by bringing it into use_react_native, similarly to what we do for Fabric and Hermes, and I've used the flag production that is already available there to decide if add or not Flipper.
That should solve this issue (even if is just a workaround), because if pod install is executed with production true, it won't add the Flipper Pods at all (differently to what CocoaPods does currently, that adds it, but doesn't copy it after is built), so Flipper won't be compiled and won't generate the mentioned error.
I'm not fully familiar with this, so any feedback is welcome :) #33882

facebook-github-bot pushed a commit that referenced this issue May 24, 2022
…lipper dependencies logic (#33882)

Summary:
This PR tries to simplify the `use_flipper` logic:
- makes `use_flipper` a configuration inside `use_react_native`'s options
- uses the already present `production` flag in the `use_react_native`'s options to decide if add or not the Flipper pods
- Simplifies the logic to download the flipper dependencies

This PR also adds a workaround for #33764

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Changed] - Move `use_flipper` logic inside `use_react_native` and simplify the Flipper dependencies logic

Pull Request resolved: #33882

Test Plan: Executed a pod install with and without flipper and with isProduction true

Reviewed By: cipolleschi

Differential Revision: D36592338

Pulled By: f-meloni

fbshipit-source-id: 3c3f773151513e27e251f18865986e942a96ffd9
jiggag added a commit to jiggag/react-native-starter that referenced this issue Jun 1, 2022
jiggag added a commit to jiggag/react-native-starter that referenced this issue Jun 1, 2022
jiggag added a commit to jiggag/react-native-starter that referenced this issue Jun 1, 2022
leotm added a commit to leotm/react-native-template-new-architecture that referenced this issue Jun 19, 2022
@leotm
Copy link
Contributor

leotm commented Jul 20, 2022

no longer getting the original issue with PRODUCTION= 1 pod install after updating Podfile, updated our template here too

but had Flipper downgrade to 0.125.0, just thinking the best way to config Flipper again for a custom/latest version

similar scenario will surface here
https://github.com/facebook/flipper/blob/main/react-native/ReactNativeFlipperExample/ios/Podfile
but not yet being on 0.67.4

maybe better opened as seperate/follow-up issue

@cortinico cortinico added the Resolution: Fixed A PR that fixes this issue has been merged. label Jul 22, 2022
@wood1986
Copy link
Contributor Author

How to specify the flipper version in 0.69.2?

@wood1986
Copy link
Contributor Author

I found it

kelset pushed a commit that referenced this issue Jul 27, 2022
Summary:
### Mentioned
- pr[main]: #33882
- discussion: reactwg/react-native-releases#21 (reply in thread)
- pr[0.69-stable]: #34098

Close: #33764

Saw the issue ago couple wks too: leotm/react-native-template-new-architecture#757
Fixed similarly: leotm/react-native-template-new-architecture#791

## Changelog

[iOS] [Changed] - Update Podfile to allow `PRODUCTION=1 pod install`

[CATEGORY] [TYPE] - Message

Pull Request resolved: #34234

Test Plan: Everything builds and runs as expected

Reviewed By: cortinico

Differential Revision: D38029117

Pulled By: cipolleschi

fbshipit-source-id: bdb58200a999cb66f1043a2feb670f9037c8e463
@leotm
Copy link
Contributor

leotm commented Aug 3, 2022

just for anyone else landing here

def self.enabled(configurations = ["Debug"], versions = {})

nicely shows how to set custom Flipper version, we were unsure about at first

so it could be worth us expanding on the comment here or adding an example for others in the future

# Enables Flipper.

will do pronto unless somebody (feel free) beats me to it :)

leotm added a commit to leotm/react-native-template-new-architecture that referenced this issue Aug 5, 2022
* Draft ios.yml

* Fix indentation

* Update ios.yml

* Build app for release

* Fix prod build error w Flipper, set env flag

Issue
- reactwg/react-native-releases#21 (comment)
- facebook/react-native#33764
PR
- facebook/react-native#33882

* Remove stale comment

* Temporarily add `npx react-native info`

* Move `npx react-native info` after `yarn`

* Add release bundle step before build

* Update bundle script

* Update bundle script

* Update RN CLI from next (8.0.0-alpha.0) to 9.0.0-alpha.5

* Remove devDep @react-native-community/cli

No luck with 9.0.0-alpha.5

Should now use npm:9.0.0-alpha.4 (via npm:^9.0.0-alpha.3)

* Try bundling also to ios/MyApp/main.jsbundle

* Add debug before release bundle/build

* Fix yarn lockfile/cache conflict res

* Add normal pod install before debug

* Comment debug pod install and build, working fine

* Update pbxproj and xcscheme

Follow-up:
- facebook/react-native#34274 (comment)

Also update parts in-line with current main
- https://github.com/facebook/react-native/tree/main/template

* Disable Metro experimentalImportSupport

* Resolve Yarn lockfile

From conflict res

* Rename xcode.env prefix _ to .

* Remove react-native-flipper

* Revert "Remove react-native-flipper"

This reverts commit 646dd74.

* Revert "Rename xcode.env prefix _ to ."

This reverts commit 8f15810.

* Revert "Disable Metro experimentalImportSupport"

This reverts commit 41ed14b.

* Add index.js for iOS Release bundling

* Add back @react-native-community/cli 9.0.0-alpha.5

* Revert "Try bundling also to ios/MyApp/main.jsbundle"

This reverts commit 80e7354.

* Revert "Comment debug pod install and build, working fine"

This reverts commit 0ea4d01.

* Update workflow comments
@stefanradu1989
Copy link

stefanradu1989 commented Nov 16, 2022

Hi,
I get this error but only when I try to archive the project so I can upload to TestFlight.
My use flipper is commented in my Podfile. (# use_flipper!())
I am running RN 0.70 Xcode 14.1

I tried the solution but it does not work:

rm -f Pods/Flipper-Folly/folly/SharedMutex.cpp Pods/Flipper-Folly/folly/SharedMutex.h
cp Pods/RCT-Folly/folly/SharedMutex.cpp Pods/Flipper-Folly/folly/
cp Pods/RCT-Folly/folly/SharedMutex.h Pods/Flipper-Folly/folly/

Did anyone solve this issue?

PS: react native info
System:
OS: macOS 13.0.1
CPU: (10) arm64 Apple M1 Pro
Memory: 55.41 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.9.0 - /usr/local/bin/node
Yarn: Not Found
npm: 8.19.1 - /usr/local/bin/npm
Watchman: 2022.09.05.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 11.0.16.1 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.4 => 0.70.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

@cipolleschi
Copy link
Contributor

@stefanradu1989 you need to reinstall the pods with PRODUCTION=1 pod install

@stefanradu1989
Copy link

@cipolleschi thank you that solved my issue

@MJ0826
Copy link

MJ0826 commented Apr 25, 2023

Hi,
I'm not sure if this is related to the same stuff being talked about here, but I am struggling with building the app while updating from react-native version 0.67.4 to 0.69.9. Does anyone have any idea what can be the reason behind this ?

Here are the screenShots -
Screenshot 2023-04-25 at 9 48 27 PM
Screenshot 2023-04-25 at 9 48 39 PM

@cipolleschi
Copy link
Contributor

@MJ0826 Can you walk throught what you did?

To me, it looks like you just run yarn update react-native or something similar, but you forget to run pod install to update the dependencies.

One thing that we did was to remove folly::Optional and replace it with std::optional, which seems the error that you are encountering. This should go away by reinstalling cocoapods with:

# from your root folder
cd ios
bundle install
bundle exec pod install

Secondly, this issue is about the New Architecture. Are you building for the New Arch or for the Legacy one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impact: Errors During Build Platform: iOS iOS applications. Priority: High Resolution: Fixed A PR that fixes this issue has been merged. Tech: React Native Core Issue related to the Core of React Native Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

Successfully merging a pull request may close this issue.