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

cocoapods integration error: undefined local variable or method `min_supported_versions' #45889

Closed
ziggear opened this issue Aug 5, 2024 · 8 comments

Comments

@ziggear
Copy link

ziggear commented Aug 5, 2024

Description

Followed instructions in React Native's official document - Environment Setup - Integration with existing apps, installed react native 0.74.0 and react 18.2.0, then add some react native's pod to my Podfile, error occurred after pod install command.

Steps to reproduce

  1. As instructed in official document, I create a package.json with content:
{
  "name": "MyReactNativeApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "yarn react-native start"
  }
}
  1. execute command: npm install react-native@0.74.0 && npm install react@18.2.0
  2. go to my Podfile, copy/paste pods listed in the document (paths already changed to the real path correctly):
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  1. execute command: pod install
  2. got the error:
Fetching podspec for `DoubleConversion` from `./RN/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
[!] Failed to load 'DoubleConversion' podspec:
[!] Invalid `DoubleConversion.podspec` file: undefined local variable or method `min_supported_versions' for Pod:Module.

 #  from /Users/ziggzhang/Workspace/AlexInputMethod/RN/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec:28
 #  -------------------------------------------
 #    # Pinning to the same version as React.podspec.
 >    spec.platforms = min_supported_versions
 #
 #  -------------------------------------------

React Native Version

0.74.0

Affected Platforms

Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 14.4.1
  CPU: (12) arm64 Apple M2 Pro
  Memory: 89.52 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 16.20.2
    path: ~/.nvm/versions/node/v16.20.2/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 7.1.0
    path: ~/node_modules/.bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.12.0
    path: /Users/ziggzhang/.rvm/gems/ruby-2.6.8/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java: Not Found
  Ruby:
    version: 2.6.8
    path: /Users/ziggzhang/.rvm/rubies/ruby-2.6.8/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: ^18.2.0
  react-native:
    installed: 0.74.4
    wanted: ^0.74.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

-> % pod install
Analyzing dependencies
Fetching podspec for `DoubleConversion` from `./RN/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
[!] Failed to load 'DoubleConversion' podspec:
[!] Invalid `DoubleConversion.podspec` file: undefined local variable or method `min_supported_versions' for Pod:Module.

 #  from /Users/ziggzhang/Workspace/AlexInputMethod/RN/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec:28
 #  -------------------------------------------
 #    # Pinning to the same version as React.podspec.
 >    spec.platforms = min_supported_versions
 #
 #  -------------------------------------------

Reproducer

https://github.com/ziggear/ZiggearRNReproducer/tree/main

Screenshots and Videos

No response

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.74.4. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@ziggear
Copy link
Author

ziggear commented Aug 5, 2024

I want to kindly point out that I checked the file located at node_modules/react-native/third-party-podspecs/DoubleConversion.podspec. It seems that this file references a min_supported_versions variable that does not exist. This appears to be a common issue across other podspecs as well.

While I understand that manually setting min_supported_versions to a specific value in each podspec could resolve the problem, I believe there might be a better practice for addressing this. Could you please provide some insight into how the official team introduces this variable and ensures it works across each podspec? Thank you for your assistance.

This issue still occurs in version 0.74.4.

@cipolleschi
Copy link
Contributor

Hi @ziggear can you share your full Podfile?
From what I can see you have a lot of pod explicitly defined that you should not have.
Also, I guess that you are calling those pod dependency before calling use_react_native!. That's the problem: that constant is defined only after the use_react_native! function is invoked.

@ziggear
Copy link
Author

ziggear commented Aug 5, 2024

Hi @ziggear can you share your full Podfile? From what I can see you have a lot of pod explicitly defined that you should not have. Also, I guess that you are calling those pod dependency before calling use_react_native!. That's the problem: that constant is defined only after the use_react_native! function is invoked.

Thanks @cipolleschi ! My Podfile is really simple because I just started a new project and tried to use the newest React Native other than the version 0.64.2 I successfully integrated before.

Thank you very much for your reminder about the use_react_native!. I apologize if I may not have fully understood the documentation. Based on the Objective-C version of the documentation, I have added pods explicitly in the Podfile. While I did find some information about use_react_native! in the Swift version's documentation, I do not have sufficient information to confirm how to use it.

Here is the full version of my project's Podfile:

platform :ios, "13.0"

target :iOSKeyboardDemo do
    pod 'CocoaAsyncSocket'
    pod 'LocalSocket', :path => './LocalSocket/'

    pod 'FBLazyVector', :path => "./RN/node_modules/react-native/Libraries/FBLazyVector"
    pod 'FBReactNativeSpec', :path => "./RN/node_modules/react-native/Libraries/FBReactNativeSpec"
    pod 'RCTRequired', :path => "./RN/node_modules/react-native/Libraries/RCTRequired"
    pod 'RCTTypeSafety', :path => "./RN/node_modules/react-native/Libraries/TypeSafety"
    pod 'React', :path => './RN/node_modules/react-native/'
    pod 'React-Core', :path => './RN/node_modules/react-native/'
    pod 'React-CoreModules', :path => './RN/node_modules/react-native/React/CoreModules'
    pod 'React-Core/DevSupport', :path => './RN/node_modules/react-native/'
    pod 'React-RCTActionSheet', :path => './RN/node_modules/react-native/Libraries/ActionSheetIOS'
    pod 'React-RCTAnimation', :path => './RN/node_modules/react-native/Libraries/NativeAnimation'
    pod 'React-RCTBlob', :path => './RN/node_modules/react-native/Libraries/Blob'
    pod 'React-RCTImage', :path => './RN/node_modules/react-native/Libraries/Image'
    pod 'React-RCTLinking', :path => './RN/node_modules/react-native/Libraries/LinkingIOS'
    pod 'React-RCTNetwork', :path => './RN/node_modules/react-native/Libraries/Network'
    pod 'React-RCTSettings', :path => './RN/node_modules/react-native/Libraries/Settings'
    pod 'React-RCTText', :path => './RN/node_modules/react-native/Libraries/Text'
    pod 'React-RCTVibration', :path => './RN/node_modules/react-native/Libraries/Vibration'
    pod 'React-Core/RCTWebSocket', :path => './RN/node_modules/react-native/'

    pod 'React-cxxreact', :path => './RN/node_modules/react-native/ReactCommon/cxxreact'
    pod 'React-jsi', :path => './RN/node_modules/react-native/ReactCommon/jsi'
    pod 'React-jsiexecutor', :path => './RN/node_modules/react-native/ReactCommon/jsiexecutor'
    pod 'React-jsinspector', :path => './RN/node_modules/react-native/ReactCommon/jsinspector'
    pod 'ReactCommon/callinvoker', :path => "./RN/node_modules/react-native/ReactCommon"
    pod 'ReactCommon/turbomodule/core', :path => "./RN/node_modules/react-native/ReactCommon"
    pod 'Yoga', :path => './RN/node_modules/react-native/ReactCommon/yoga'

    pod 'DoubleConversion', :podspec => './RN/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
    pod 'glog', :podspec => './RN/node_modules/react-native/third-party-podspecs/glog.podspec'
    pod 'Folly', :podspec => './RN/node_modules/react-native/third-party-podspecs/Folly.podspec'
end

target :KeyboardExtension do
    pod 'CocoaAsyncSocket'
    pod 'LocalSocket', :path => './LocalSocket/'
end

@okwasniewski
Copy link
Contributor

@ziggear Your Podfile should look something like this:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

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 'NativeExample' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    :app_path => "#{Pod::Config.instance.installation_root}/../.."
  )

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/ react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )
  end
end

You can check out an example of brownfield integration for both Swift and Objective-C in this repo: https://github.com/callstack/react-native-brownfield/tree/master/example/objc

@ziggear
Copy link
Author

ziggear commented Aug 6, 2024

@ziggear Your Podfile should look something like this:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

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 'NativeExample' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    :app_path => "#{Pod::Config.instance.installation_root}/../.."
  )

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/ react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )
  end
end

You can check out an example of brownfield integration for both Swift and Objective-C in this repo: https://github.com/callstack/react-native-brownfield/tree/master/example/objc

Thanks @okwasniewski it works for me!

By the way I believe this could be a documentation issue for the Objective-C developer to integrate initially newest react native to their project: the documentation still suggest to add pods explicitly:

image

@ziggear ziggear closed this as completed Aug 6, 2024
@okwasniewski
Copy link
Contributor

The documentation on this topic is unfortunately outdated. I'm happy that you managed to get it working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants