react native 0.81 初始化工程

53 阅读1分钟

参考 reactnative.dev/docs/gettin…

Step 3: Start your application

yarn start
yarn ios

启动 ios 模拟器遇到问题 react native installing cocoapods dependencies error

google ai 给出的方法


Encountering errors when installing CocoaPods dependencies in a React Native project is a common issue, often related to the Ruby environment or CocoaPods installation itself. Here are common solutions to address these errors:

  1. Ruby Environment Issues:
  • Ensure Correct Ruby Version:  CocoaPods often requires a specific Ruby version. Verify your current Ruby version with ruby --version. If it's outdated or incompatible, use a Ruby version manager like rbenv or RVM to install and switch to a compatible version.
# Example using rbenv
brew install rbenv ruby-build
rbenv init
echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc # or ~/.bash_profile
source ~/.zshrc # or ~/.bash_profile
rbenv install 3.2.2 # Or the required version
rbenv global 3.2.2
  • Avoid System Ruby:  It's generally recommended to install Ruby using Homebrew or a version manager rather than relying on the system's default Ruby, which can lead to permission issues.
  1. CocoaPods Installation Issues:
  • Install/Update CocoaPods:  Ensure CocoaPods is installed and up-to-date.
sudo gem install cocoapods

If you encounter permission errors, consider using sudo.

  • Permission Errors:  If pod install fails with permission errors, it might be due to CocoaPods being installed without sudo. Reinstalling with sudo gem install cocoapods can resolve this.
  • Corrupted Pods Cache:  Sometimes, clearing the CocoaPods cache can help.
rm -rf Pods
rm Podfile.lock
pod cache clean --all
cd ios && pod install
  1. React Native Specific Issues:
  • Navigate to ios Directory: Ensure you are in the ios directory of your React Native project when running pod install.
cd ios
pod install
  • npx expo install --fix (for Expo projects): 

    If you are using Expo, this command can help resolve dependency issues and potentially fix CocoaPods-related problems.

  • Rebuild iOS Directory (for Expo projects):  

    If issues persist in an Expo project, try removing the ios directory and regenerating it using npx expo prebuild.

  1. General Troubleshooting:
  • Xcode Command Line Tools:  Ensure your Xcode Command Line Tools are updated.
xcode-select --install
  • Xcode Version Compatibility:  

    Verify that your Xcode version is compatible with your React Native and CocoaPods versions.

  • Path Issues:  

    Avoid project paths containing special characters or spaces, which can sometimes interfere with build tools.

  • Verbose Output:  

    Run pod install --verbose to get more detailed error messages, which can provide clues for specific issues.