简体   繁体   English

启动新的 React Native 项目时安装 CocoaPods 依赖项时出错

[英]Error Installing CocoaPods dependencies when initiating new React Native project

I tried to create new React Native project and it failed due to error of multiple podfiles were found.我尝试创建新的 React Native 项目,但由于发现多个 podfiles 错误而失败。

error: warn Multiple Podfiles were found: ios/Podfile,vendor/bundle/ruby/2.7.0/gems/cocoapods-core-1.11.3/lib/cocoapods-core/Podfile. Choosing ios/Podfile automatically. If you would like to select a different one, you can configure it via "project.ios.sourceDir". You can learn more about it here: https://github.com/react-native-community/cli/blob/master/docs/configuration.md

Same here, below some more details to help solving issue.同样在这里,下面是一些有助于解决问题的更多细节。 Fresh new Macbook Pro (M1 Pro) and after following installation steps from rn docs.全新的 Macbook Pro (M1 Pro) 并按照 rn 文档中的安装步骤进行操作。 Same error when init newest version, also same with 0.69.0 npx react-native init AwesomeProject :初始化最新版本时出现同样的错误,也与 0.69.0 npx npx react-native init AwesomeProject

✖ Installing CocoaPods dependencies (this may take a few minutes)
error warn Multiple Podfiles were found: ios/Podfile,vendor/bundle/ruby/2.7.0/gems/cocoapods-core-1.11.3/lib/cocoapods-core/Podfile. Choosing ios/Podfile automatically. If you would like to select a different one, you can configure it via "project.ios.sourceDir". You can learn more about it here: https://github.com/react-native-community/cli/blob/master/docs/configuration.md

✖ Installing CocoaPods dependencies (this may take a few minutes)
error Error: Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/next/environment-setup and follow the React Native CLI QuickStart guide for macOS and iOS.

.zshrc .zshrc

export PATH=/opt/homebrew/bin:$PATH
eval "$(rbenv init - zsh)

"

.zprofile .z配置文件

eval "$(/opt/homebrew/bin/brew shellenv)"
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools

xcode 14代码 14

After

 ruby --version
 brew info cocoapods

i get:我得到:

    ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [arm64-darwin21]
    /opt/homebrew/Cellar/cocoapods/1.11.3

I don't understand why its creating new folder with ruby cocoapods inside my rn project: /vendor Never had that issue on my older M1.我不明白为什么它会在我的 rn 项目中创建带有 ruby cocoapods 的新文件夹: /vendor在我的旧 M1 上从来没有遇到过这个问题。 I already tried with sudo arch -x86_64 gem install ffi我已经尝试过sudo arch -x86_64 gem install ffi

EDIT 1: pod install --project-directory=ios shows me error similar to another cocoaPods issue but didnt fix编辑 1: pod install --project-directory=ios向我显示类似于另一个cocoaPods 问题但未修复的错误

Answer in that issue helped.该问题的答案有所帮助。 Try:尝试:

sudo xcode-select --switch /Applications/Xcode.app

It fixed my errors and allowed me to build 0.70.3 rn init.它修复了我的错误并允许我构建 0.70.3 rn init。 But before that i've also downgrade my xcode to 13.4, not sure if it was necessary.但在那之前我也将我的 xcode 降级到 13.4,不确定是否有必要。

But still i get this strange /vendor folder in my rn app, but after deleting it its still building fine on ios.但我仍然在我的 rn 应用程序中得到这个奇怪的 /vendor 文件夹,但在删除它之后它仍然在 ios 上正常构建。

Create a file called react-native.config.js at the root level of your project with the following contents:使用以下内容在项目的根级别创建一个名为react-native.config.js的文件:

module.exports = {
    project: {
        ios: {
            sourceDir: './ios',
        },
    },
};

Then when you run npx react-native run-ios the Podfile in the ios/ directory will by chosen and you won't see the error.然后,当您运行 npx npx react-native run-ios时, ios/ 目录中的 Podfile 将被选中,您将不会看到错误。

Maybe this is just me but this was my experience and fix:也许这只是我,但这是我的经验和解决方法:

First when I ran xcode-select -p it was returning /Library/Developer/CommandLineTools首先,当我运行xcode-select -p时,它返回/Library/Developer/CommandLineTools

However this looked odd as another an answer here seemed to suggest that maybe this was causing an issue.然而,这看起来很奇怪,因为这里的另一个答案似乎表明这可能导致了问题。 It ended up that I just hadn't set my CLI tools correctly as described in the react native docs.结果是我没有按照 react native 文档中的描述正确设置我的 CLI 工具。 Since it only had one option in the dropdown I assumed that the CLI tools were already set.因为它在下拉列表中只有一个选项,所以我假设 CLI 工具已经设置好了。 However when I went back and specifically clicked on the one option, it made changes to my system.但是,当我返回并专门单击一个选项时,它对我的系统进行了更改。

Now running xcode-select -p returns现在运行xcode-select -p返回

/Application/Xcode.app/Contents/Developer

TL;DR: Open Xcode, go to 'Settings...' in the menu bar. TL;DR:打开 Xcode,转到菜单栏中的“设置...”。 Then go to the 'Locations' tab and click on the 'Command Line Tools' dropdown and click on the latest version (click on a version even if it seems like a version is already set).然后转到“位置”选项卡并单击“命令行工具”下拉菜单并单击最新版本(即使看起来已经设置了一个版本,也请单击一个版本)。 Now try your pod install again!现在再次尝试安装 pod!

can you try - pod install --project-directory=ios你能试试 - pod install --project-directory=ios

Make sure you enabled command line tools in Xcode.确保您在 Xcode 中启用了命令行工具。 Xcode --> settings ---> Locations ---> Command line tools enter image description here Xcode --> settings ---> Locations ---> Command line tools enter image description here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM