diff --git a/packages/react-native/scripts/cocoapods/helpers.rb b/packages/react-native/scripts/cocoapods/helpers.rb index 1e115ef1755528..68017d1f0cc535 100644 --- a/packages/react-native/scripts/cocoapods/helpers.rb +++ b/packages/react-native/scripts/cocoapods/helpers.rb @@ -41,6 +41,10 @@ def self.min_ios_version_supported return '13.4' end + def self.min_xcode_version_supported + return '14.3' + end + def self.folly_config return { :version => '2024.01.01.00', diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index ffe6a70c7e95ca..8873af4860440c 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -407,19 +407,39 @@ def self.remove_value_from_setting_if_present(config, setting_name, value) def self.is_using_xcode15_0(xcodebuild_manager: Xcodebuild) xcodebuild_version = xcodebuild_manager.version + if version = self.parse_xcode_version(xcodebuild_version) + return version["major"] == 15 && version["minor"] == 0 + end + + return false + end + + def self.parse_xcode_version(version_string) # The output of xcodebuild -version is something like # Xcode 15.0 # or # Xcode 14.3.1 # We want to capture the version digits - regex = /(\d+)\.(\d+)(?:\.(\d+))?/ - if match_data = xcodebuild_version.match(regex) - major = match_data[1].to_i - minor = match_data[2].to_i - return major == 15 && minor == 0 + match = version_string.match(/(\d+)\.(\d+)(?:\.(\d+))?/) + return nil if match.nil? + + return {"str" => match[0], "major" => match[1].to_i, "minor" => match[2].to_i}; + end + + def self.check_minimum_required_xcode(xcodebuild_manager: Xcodebuild) + version = self.parse_xcode_version(xcodebuild_manager.version) + if (version.nil? || !Gem::Version::correct?(version["str"])) + Pod::UI.warn "Unexpected XCode version string '#{xcodebuild_manager.version}'" + return end - return false + current = version["str"] + min_required = Helpers::Constants.min_xcode_version_supported + + if Gem::Version::new(current) < Gem::Version::new(min_required) + Pod::UI.puts "React Native requires XCode >= #{min_required}. Found #{current}.".red + raise "Please upgrade XCode" + end end def self.add_compiler_flag_to_project(installer, flag, configuration: nil) diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index e60920404de575..462048d89962ca 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -80,6 +80,8 @@ def use_react_native! ( ENV['APP_PATH'] = app_path ENV['REACT_NATIVE_PATH'] = path + ReactNativePodsUtils.check_minimum_required_xcode() + # Current target definition is provided by Cocoapods and it refers to the target # that has invoked the `use_react_native!` function. ReactNativePodsUtils.detect_use_frameworks(current_target_definition)