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 for IOS after enabling new architecture, #37102

Closed
kaushal9808 opened this issue Apr 26, 2023 · 10 comments
Closed

Unable to Build for IOS after enabling new architecture, #37102

kaushal9808 opened this issue Apr 26, 2023 · 10 comments
Labels
Platform: iOS iOS applications. Resolution: PR Submitted A pull request with a fix has been provided. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@kaushal9808
Copy link

Description

We are using react native 0.71.7 version without enabling new architecture its working fine for both platform android and ios.
But After Enabling New Architecture build failing for Ios, Android Build working fine.
we are getting linking error

Undefined symbols for architecture x86_64:
"_RCTAppSetupDefaultModuleFromClass", referenced from:
-[RCTAppDelegate getModuleInstanceFromClass:] in libReact-RCTAppDelegate.a(RCTAppDelegate.o)
"RCTAppSetupDefaultJsExecutorFactory(RCTBridge*, RCTTurboModuleManager*)", referenced from:
-[RCTAppDelegate jsExecutorFactoryForBridge:] in libReact-RCTAppDelegate.a(RCTAppDelegate.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

React Native Version

0.71.7

Output of npx react-native info

info Fetching system and libraries information...
System:
OS: macOS 13.3.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 897.02 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.9.0 - /usr/local/bin/node
Yarn: Not Found
npm: 9.6.3 - /usr/local/bin/npm
Watchman: 2023.04.10.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.12.0 - /Users/XYZ/.rvm/gems/ruby-2.7.6/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
Android SDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9619390
Xcode: 14.3/14E222b - /usr/bin/xcodebuild
Languages:
Java: 11.0.18 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

Enable New Architecture using RCT_NEW_ARCH_ENABLED=1 && pod install
and build from xcode version 14.3

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

I have tried with arm64 active arch.

@kaushal9808 kaushal9808 added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Apr 26, 2023
@github-actions github-actions bot added the Platform: iOS iOS applications. label Apr 26, 2023
@cortinico
Copy link
Contributor

cc @cipolleschi

@cipolleschi
Copy link
Contributor

Hi @kaushal9808, thanks for the issue. Could you please provide a reproducer?

I tried to create a new app, install the pods and build with Xcode 14.3 as you suggested, but new apps build fine, so I guess there is something specific of your setup...

What I run:

npx react-native init NewArchTest --version 0.71.7 --skip-install
cd NewArchTest
yarn
cd ios
bundle install
RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
open NewArchTest.xcworkspace

+ r

@kaushal9808
Copy link
Author

we have migrated our app from RN - 0.67.0 version to 0.71.7, Android and IOS version without new architecture working fine,
After Enable the New Architecture Android is also working fine, But we are facing this issues only for iOS. I am working on it if I found more information then will update here, repository is private so currently we can unable to share the same.
we are checking with new init project and migrating our project, if that's work then great.

Could you please share ruby version with using -> npx react-native info

we can check that if that will create issues or not.

@cipolleschi
Copy link
Contributor

version 0.71.7 dropped any requirement for Ruby. Everything should work from version 2.6.10, shipped with the Macbook to version 3.2.0.

We also have test in CircleCI that builds React Native in a new app from the template using Ruby 2.7.7 (latest Ruby 2 stable) and Ruby 3.2.0.

Personally, my global ruby version, through rbenv is 3.2.0. But I don't think that Ruby is the problem.

Can you share the Podfile at least? Also, can you confirm that you reinstall the pods?

@kaushal9808
Copy link
Author

kaushal9808 commented May 4, 2023

Hello ,

for PodFile reference, I have copy paste it here . and I have reinstall pods multiple times after removing cache as well.
I think react-native-cli or may other lib will create this issues.
And yes Ruby version is expected as you have mentioned 3.2.0 right now, but we have tested with gt 2.7.0. yes Ruby version is the not the one.

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'

platform :ios, min_ios_version_supported

prepare_react_native_project!
ENV['RCT_NEW_ARCH_ENABLED'] = "1"
# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
	if linkage != nil
	  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
	  use_frameworks! :linkage => linkage.to_sym
  end

target 'XXXX' do
  config = use_native_modules!

  # For extensions without React dependencies
  pod 'react-native-config', :path => '../node_modules/react-native-config'
  
  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'XXXX' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    installer.pods_project.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end
    ################### ADD THE FOLLOWING #########################
        installer.pods_project.targets.each do |target|
          if target.name == "React-Core.common-AccessibilityResources"
            target.remove_from_project
          end
        end
        ###############################################################
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

@cipolleschi
Copy link
Contributor

I think I got the problem. The error reports that the RCTAppSetupDefaultModuleFromClass and RCTAppSetupDefaultJsExecutorFactory symbols are not found.

If we look at the RCTAppSetupUtils class, this symbols are protected behind a flag RCT_NEW_ARCH_ENABLED=1.

What's happening is that the flag is not propagated to the pod, so those symbols are actually excluded from the build. This code should make sure that those flag are set, but there could be a bug there. Or there could be some other pieces of infra that tinkers with the C/CXX flags we are setting up.

To double check that that's the problem, you can:

  1. open the xcworkspace,
  2. open the Pods project,
  3. select the React-Core pod, // <-- this changed in 0.72
  4. select Build Settings
  5. filter for OTHER_CPLUSPLUS_FLAGS
  6. You should see that like this:

Screenshot 2023-05-04 at 15 01 04

@kaushal9808
Copy link
Author

Thanks Buddy, Perfect Catch. In Our Case Two React-core is created and I have added these parameter in both react core, now it's building successfully.

I do not know the reason about two react-core right now, I have attached the screenshot for reference.
Screenshot 2023-05-04 at 10 07 26 PM

@cipolleschi
Copy link
Contributor

That's effectively weird. I don't know how's possible that you have two React-Core... 😅
Let me know if you find the reason. I'm closing the issue as it seems like we found the root cause but there is no direct actionable for the React Native framework.

@douglowder
Copy link
Contributor

@cipolleschi It is very possible to have two React-Core if you have multiple targets, as we do for the TV repo. In this case, instead of just 'React-Core', we have 'React-Core-iOS' and 'React-Core-tvOS'.

This patch fixed the issue for me. If you agree that this is reasonable, I can open a PR to the core repo.

diff --git a/node_modules/react-native/scripts/cocoapods/new_architecture.rb b/node_modules/react-native/scripts/cocoapods/new_architecture.rb
index 90141cd..6ef1de9 100644
--- a/node_modules/react-native/scripts/cocoapods/new_architecture.rb
+++ b/node_modules/react-native/scripts/cocoapods/new_architecture.rb
@@ -16,7 +16,7 @@ class NewArchitectureHelper
         language_standard = nil
 
         installer.pods_project.targets.each do |target|
-            if target.name == 'React-Core'
+            if target.name.include? 'React-Core'
                 language_standard = target.resolved_build_setting("CLANG_CXX_LANGUAGE_STANDARD", resolve_against_xcconfig: true).values[0]
             end
         end
@@ -54,7 +54,7 @@ class NewArchitectureHelper
 
         # Add RCT_NEW_ARCH_ENABLED to generated pod target projects
         installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result|
-            if pod_name == 'React-Core'
+            if pod_name.include? 'React-Core'
                 target_installation_result.native_target.build_configurations.each do |config|
                     config.build_settings['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags
                 end

@cipolleschi
Copy link
Contributor

@douglowder as temporary patch/fixes, would you mind set up a PR for this? 🙏

@Pranav-yadav Pranav-yadav added Resolution: PR Submitted A pull request with a fix has been provided. and removed Needs: Triage 🔍 labels May 26, 2023
facebook-github-bot pushed a commit that referenced this issue May 30, 2023
…targets (#37581)

Summary:
In Xcode projects with multiple targets, and in particular when targets are for different platforms (e.g. iOS and macOS), Cocoapods may add a suffix to a Pod name like `React-Core`.

When this happens, the code in `new_architecture.rb` (which was looking for a pod with exact name `React-Core`) would not add the preprocessor definitions for Fabric as expected.

This change fixes this issue. Fixes #37102 .

## Changelog:

[iOS] [Fixed] - Fix Fabric issue with React-Core pod when Xcode project has multiple targets

Pull Request resolved: #37581

Test Plan: Tested that this change fixes this issue which occurs 100% of the time in React Native TV projects.

Reviewed By: dmytrorykun

Differential Revision: D46264704

Pulled By: cipolleschi

fbshipit-source-id: 8dfc8e342b5a110ef1f028636e01e5c5f2b6e2f0
Szymon20000 pushed a commit to Szymon20000/react-native that referenced this issue Jun 14, 2023
…targets (facebook#37581)

Summary:
In Xcode projects with multiple targets, and in particular when targets are for different platforms (e.g. iOS and macOS), Cocoapods may add a suffix to a Pod name like `React-Core`.

When this happens, the code in `new_architecture.rb` (which was looking for a pod with exact name `React-Core`) would not add the preprocessor definitions for Fabric as expected.

This change fixes this issue. Fixes facebook#37102 .

## Changelog:

[iOS] [Fixed] - Fix Fabric issue with React-Core pod when Xcode project has multiple targets

Pull Request resolved: facebook#37581

Test Plan: Tested that this change fixes this issue which occurs 100% of the time in React Native TV projects.

Reviewed By: dmytrorykun

Differential Revision: D46264704

Pulled By: cipolleschi

fbshipit-source-id: 8dfc8e342b5a110ef1f028636e01e5c5f2b6e2f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: iOS iOS applications. Resolution: PR Submitted A pull request with a fix has been provided. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
5 participants