RN环境配置(这里只演示mac版本的android studio的sdk下载失败的解决和ios环境的配置)

1.前期准备

NVM下载和使用
JDK下载和安装
下面这个jdk的安装和配置有配置环境变量的,下面的安卓sdk环境变量配置跟这个是差不多的也是一样的命令

2.android sdk下载失败情况

参考这篇博客就行
提供一个梯子地址 https://ikuuu.pw/

本人的环境配置

export ANDROID_HOME=/Users/admin/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/emulator
// 上面是安卓sdk配置
// 下面这个是jdk环境配置
export JAVA_HOME=/Users/admin/Desktop/jdk-17.0.10.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH
export PATH
export CLASSPATH

3.ios环境配置

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • 安装 Node(前面安装过nvm就可以了) 和 Watchman(这个我没下载,本人下载了各种报错),因此本人这一步省略了,有需要的朋友可以下载
    1. 安装yarn
npm install -g yarn
    1. 安装Xcode(这个各位百度自行下载配置)
    1. 安装cocoapods
brew install cocoapods
    1. 创建项目
npx react-native init AwesomeProject
  • 7.在项目下的ios文件夹打开终端输入以下命令安装ios依赖
pod install

bug

执行pod install可能会遇到[!] Failed to load 'glog' podspec: [!] Invalid glog.podspecfile: undefine或者yarn run ios遇到下面

error Error: Command failed with exit code 1: xcodebuild -list -json
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance.
Error: Error: Command failed with exit code 1: xcodebuild -list -json
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
    at getInfo (/Users/admin/Desktop/project/ben/Demo2/node_modules/@react-native-community/cli-platform-ios/build/tools/getInfo.js:31:11)
    at getConfiguration (/Users/admin/Desktop/project/ben/Demo2/node_modules/@react-native-community/cli-platform-ios/build/commands/buildIOS/getConfiguration.js:34:37)
    at Object.runIOS [as func] (/Users/admin/Desktop/project/ben/Demo2/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js:115:52)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.handleAction (/Users/admin/Desktop/project/ben/Demo2/node_modules/@react-native-community/cli/build/index.js:118:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

这种错误,只需要在终端输入以下命令即可解决

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

这会将 Xcode 开发者目录设置为 Xcode 应用程序的目录。并确认已经安装了 Xcode,并且路径正确。
然后重新pod install和yarn run ios即可
如果问题仍然存在,可以尝试清除项目的缓存并重新构建项目:

yarn cache clean
cd ios
rm -rf Pods Podfile.lock
pod install
cd ..
yarn run ios
  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萧寂173

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值