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

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-24 07:06:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-24 07:06:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-24 07:06:02       82 阅读
  4. Python语言-面向对象

    2024-03-24 07:06:02       91 阅读

热门阅读

  1. 二进制源码部署mysql8.0.35

    2024-03-24 07:06:02       31 阅读
  2. node.js中常用的命令及示例

    2024-03-24 07:06:02       36 阅读
  3. Node.js 常用命令

    2024-03-24 07:06:02       41 阅读
  4. 算法提高篇基础算法第一章 - 贪心算法

    2024-03-24 07:06:02       34 阅读
  5. 计算机二级真题讲解每日一题:《format格式化》

    2024-03-24 07:06:02       33 阅读
  6. Android单片机硬件通信《GPIO通信》

    2024-03-24 07:06:02       34 阅读
  7. 设计模式(行为型设计模式——模板方法模式)

    2024-03-24 07:06:02       36 阅读
  8. Unity与鼠标相关的事件(自己记忆用)

    2024-03-24 07:06:02       35 阅读