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

1.前期准备

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

2.android sdk下载失败情况

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

本人的环境配置

js 复制代码
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环境配置

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

bug

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

js 复制代码
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.

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

js 复制代码
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

这会将 Xcode 开发者目录设置为 Xcode 应用程序的目录。并确认已经安装了 Xcode,并且路径正确。
然后重新pod install和yarn run ios即可

如果问题仍然存在,可以尝试清除项目的缓存并重新构建项目:

js 复制代码
yarn cache clean
cd ios
rm -rf Pods Podfile.lock
pod install
cd ..
yarn run ios
相关推荐
Android出海3 小时前
iOS 出海新门槛:未成年人合规来了
ios·app store·ios开发·苹果开发者·ios开发者·ios出海
2501_915106324 小时前
iOS 软件测试工具性能监控、日志分析 KeyMob、Instruments等
android·ios·小程序·https·uni-app·iphone·webview
木叶丸5 小时前
AI 编程概念与 Harness 工程实践入门
人工智能·flutter·ios
zzb15806 小时前
Zed 配置 Swift / iOS 开发
开发语言·ios·swift
鱼儿也有烦恼1 天前
01.搭建Android Studio开发环境
android·android studio
colman wang1 天前
Git指令(Mac)
git·macos
黑科技iOS上架1 天前
如何解决AppStore Guideline 5.6被拒
经验分享·ios·ai编程
韩曙亮1 天前
【Flutter】iOS 网络权限设置 ① ( WLAN/蜂窝全局联网权限设置 )
网络·flutter·ios·网络权限
Geek-Chow1 天前
Mobile App Certificate Pinning: Underlying Principle and a Swift Example
开发语言·ios·swift·安全架构
韩曙亮1 天前
【Flutter】iOS 网络权限设置 ② ( 配置 iOS 平台可使用 HTTP 访问 | ATS 网络安全强制规范 )
网络·flutter·http·ios·https·网络权限·ats