Skip to content

Automate setting the RCTNewArchEnabled flag #49927

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

Closed
wants to merge 2 commits into from

Conversation

cipolleschi
Copy link
Contributor

Summary:
This change automates updating App's Info.plist with the new RCTNewArchEnabled boolean entry. The value depends on how the pod install is set up. In this way, we maintain the previous UX to enable/disable the New Arch.

Context

The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not.

However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example:

  • New Arch / Hermes
  • Old Arch / Hermes
  • New Arch / JSC
  • Old Arch / JSC
  • ...

Backward compatibility

We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself.

Changelog:

[iOS][Added] -

Reviewed By: cortinico

Differential Revision: D70888212

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 10, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70888212

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Mar 10, 2025
Summary:

This change automates updating App's Info.plist with the new `RCTNewArchEnabled` boolean entry. The value depends on how the pod install is set up. In this way, we maintain the previous UX to enable/disable the New Arch.


## Context
The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not.

However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example:

- New Arch / Hermes
- Old Arch / Hermes
- New Arch / JSC
- Old Arch / JSC
- ...

## Backward compatibility
We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself.

## Changelog:
[iOS][Added] -

Reviewed By: cortinico

Differential Revision: D70888212
Summary:

This change deprecates the RCT_NEW_ARCH_ENABLEd flag to toggle the New Architecture.

The new approach bring iOS closer to Android: to diasable the New Architecture, user needs to modify the App's Info.plist and add a `RCTNewArchEnabled` boolean entry and set it to `NO`.

The absence of the entry implies that the New Arch is enabled. (Defaults to enabled)

This also deprecates the `RCTSetNewArchEnabled` function because it makes no sense now

## Context
The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not.

However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example:

- New Arch / Hermes
- Old Arch / Hermes
- New Arch / JSC
- Old Arch / JSC
- ...

## Backward compatibility
We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself.

## Changelog:
[iOS][Deprecated] - deprecate the `RCT_NEW_ARCH_ENABLED` and the `RCTSetNewArchEnabled`

Reviewed By: cortinico

Differential Revision: D70885454
Summary:

This change automates updating App's Info.plist with the new `RCTNewArchEnabled` boolean entry. The value depends on how the pod install is set up. In this way, we maintain the previous UX to enable/disable the New Arch.


## Context
The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not.

However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example:

- New Arch / Hermes
- Old Arch / Hermes
- New Arch / JSC
- Old Arch / JSC
- ...

## Backward compatibility
We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself.

## Changelog:
[iOS][Added] -

Reviewed By: cortinico

Differential Revision: D70888212
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70888212

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Mar 10, 2025
Summary:

This change automates updating App's Info.plist with the new `RCTNewArchEnabled` boolean entry. The value depends on how the pod install is set up. In this way, we maintain the previous UX to enable/disable the New Arch.


## Context
The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not.

However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example:

- New Arch / Hermes
- Old Arch / Hermes
- New Arch / JSC
- Old Arch / JSC
- ...

## Backward compatibility
We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself.

## Changelog:
[iOS][Added] -

Reviewed By: cortinico

Differential Revision: D70888212
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Mar 10, 2025
Summary:

This change automates updating App's Info.plist with the new `RCTNewArchEnabled` boolean entry. The value depends on how the pod install is set up. In this way, we maintain the previous UX to enable/disable the New Arch.


## Context
The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not.

However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example:

- New Arch / Hermes
- Old Arch / Hermes
- New Arch / JSC
- Old Arch / JSC
- ...

## Backward compatibility
We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself.

## Changelog:
[iOS][Added] -

Reviewed By: cortinico

Differential Revision: D70888212
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 11, 2025
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 3b3d502.

facebook-github-bot pushed a commit that referenced this pull request Jun 5, 2025
…es (#51833)

Summary:
#49927 introduced a regression where a Ruby script would read compilation artifacts and fail, when the user has relative build directories set in XCode.

After successful compilation `build/` dir and `DerivedData/` dir have `.plist` files that aren't in UTF-8 encoding and shouldn't be read by the script. If the user tries to reinstall pods at this point, he gets the following error:

![image](https://github.com/user-attachments/assets/6bd31907-66af-4ea5-b2a6-2847e0ee18e1)

This is how you enable relative build directories in XCode.

![Screenshot 2025-06-05 at 11 08 31](https://github.com/user-attachments/assets/22a555b4-a468-481d-8492-02c3b36bfa25)

## Changelog:

[IOS] [FIXED] - Ignore `build/` and `DerivedData/` directories when reading `.plist` files.

Pull Request resolved: #51833

Test Plan: After applying this patch the problem doesn't occur anymore on my machine.

Reviewed By: cortinico

Differential Revision: D76030133

Pulled By: cipolleschi

fbshipit-source-id: 7ae8c2d0ce28b6925245a9172154e3dcafee126f
react-native-bot pushed a commit that referenced this pull request Jun 9, 2025
…es (#51833)

Summary:
#49927 introduced a regression where a Ruby script would read compilation artifacts and fail, when the user has relative build directories set in XCode.

After successful compilation `build/` dir and `DerivedData/` dir have `.plist` files that aren't in UTF-8 encoding and shouldn't be read by the script. If the user tries to reinstall pods at this point, he gets the following error:

![image](https://github.com/user-attachments/assets/6bd31907-66af-4ea5-b2a6-2847e0ee18e1)

This is how you enable relative build directories in XCode.

![Screenshot 2025-06-05 at 11 08 31](https://github.com/user-attachments/assets/22a555b4-a468-481d-8492-02c3b36bfa25)

## Changelog:

[IOS] [FIXED] - Ignore `build/` and `DerivedData/` directories when reading `.plist` files.

Pull Request resolved: #51833

Test Plan: After applying this patch the problem doesn't occur anymore on my machine.

Reviewed By: cortinico

Differential Revision: D76030133

Pulled By: cipolleschi

fbshipit-source-id: 7ae8c2d0ce28b6925245a9172154e3dcafee126f
@alimek
Copy link

alimek commented Jun 16, 2025

hey @cipolleschi

I have issues with the code after update to RN 0.80, this is probably specified to my codebase but just want to ask if this should be handled here or i need to play with this on our side.

I use one 3rd party framework, which just sits in the /ios directory which include Info.plist file and it is encoded,

the code

info_plist = Xcodeproj::Plist.read_from_path(infoPlistFile)

is just throwing error

[!] An error occurred while processing the post-install hook of the Podfile.

invalid byte sequence in UTF-8

XXX/react-native/vendor/bundle/ruby/3.4.0/gems/xcodeproj-1.25.1/lib/xcodeproj/plist.rb:91:in 'Regexp#match'
XXX/react-native/vendor/bundle/ruby/3.4.0/gems/xcodeproj-1.25.1/lib/xcodeproj/plist.rb:91:in 'String#match'
XXX/react-native/vendor/bundle/ruby/3.4.0/gems/xcodeproj-1.25.1/lib/xcodeproj/plist.rb:91:in 'Xcodeproj::Plist.file_in_conflict?'
XXX/react-native/vendor/bundle/ruby/3.4.0/gems/xcodeproj-1.25.1/lib/xcodeproj/plist.rb:20:in 'Xcodeproj::Plist.read_from_path'
XXX/react-native/node_modules/react-native/scripts/cocoapods/new_architecture.rb:182:in 'block (2 levels) in NewArchitectureHelper.set_RCTNewArchEnabled_in_info_plist'
XXX/react-native/node_modules/react-native/scripts/cocoapods/new_architecture.rb:170:in 'Array#each'
XXX/react-native/node_modules/react-native/scripts/cocoapods/new_architecture.rb:170:in 'block in NewArchitectureHelper.set_RCTNewArchEnabled_in_info_plist'
XXX/react-native/node_modules/react-native/scripts/cocoapods/new_architecture.rb:165:in 'Array#each'
XXX/react-native/node_modules/react-native/scripts/cocoapods/new_architecture.rb:165:in 'NewArchitectureHelper.set_RCTNewArchEnabled_in_info_plist'

changing code in new_architecutre.rb from:

info_plist = Xcodeproj::Plist.read_from_path(infoPlistFile)
 # Check if it contains the RCTNewArchEnabled key
 if info_plist["RCTNewArchEnabled"] and info_plist["RCTNewArchEnabled"] == new_arch_enabled
     next
 end

 # Add the key and value to the plist
 info_plist["RCTNewArchEnabled"] = new_arch_enabled ? true : false
 Xcodeproj::Plist.write_to_path(info_plist, infoPlistFile)

to:

begin
    # Read the file as a plist
    info_plist = Xcodeproj::Plist.read_from_path(infoPlistFile)
    # Check if it contains the RCTNewArchEnabled key
    if info_plist["RCTNewArchEnabled"] and info_plist["RCTNewArchEnabled"] == new_arch_enabled
        next
    end

    # Add the key and value to the plist
    info_plist["RCTNewArchEnabled"] = new_arch_enabled ? true : false
    Xcodeproj::Plist.write_to_path(info_plist, infoPlistFile)
rescue => e
    puts "Failed to read plist from #{infoPlistFile}: #{e.message}"
    next
end

but I am not sure if that's okey, please let me know and I can maybe create PR if that's okey or made some other path if you have better view ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants