likes
comments
collection
share

react native 0.71 Intel mac 下的环境设置

作者站长头像
站长
· 阅读数 10

react native 0.71 Intel mac 下的环境设置

apple M 系列的应该问题也不大,如有需要我会补充

准备 ios 开发环境

  • install oh-my-zsh
  • install homebrew-CN
  • install nvm node
  • install nrm
    • nrm ls
    • nrm use taobao
    • npm i -g yarn pnpm nodemon http-server ts-node
  • install xcode
  • brew install ruby

brew 安装的 ruby 可能需要一些配置

export PATH="/usr/local/opt/ruby/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"

创建 react-native 项目

  • npx react-native init lesson1 --template react-native-template-typescript

在这里最后一步安装依赖一定会出错,主要是 cocoapod 安装依赖,要么去 rubygems.org 要么去 github 里面会下载大约 2G 大小的依赖,这两个域名容易访问慢,我也不知道为什么。

  • 执行 pod repo update --verbose

  • 1 找到 react-native 项目根目录的 Gemfile 文件,如 /Users/mac/Desktop/program-demo-sets/react-native--learn/lesson2/Gemfile 注释掉 # source 'https://rubygems.org' 新增 source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

  • 2 找到 react-native 项目根目录下的 ios 目录里面的 Podfile, 如 /Users/mac/Desktop/program-demo-sets/react-native--learn/lesson1/ios/Podfile 的第一行之上添加一行,内容为 source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git

在此时如果有已经下载好依赖的 react-native 项目,则复制 ios 目录下的 Pods 目录里面的全部文件到新项目的 ios 目录下的 Pods 里面,这样可以避免翻墙,下载依赖,否则就准备好梯子反复下载吧。

复制完有以后在 ios 目录执行

bundle install
bundle exec pod install
  • cd /Users/mac/Desktop/program-demo-sets/react-native--learn/lesson1/ios/ ios 目录内执行如下命令

If you are having trouble with iOS, try to reinstall the dependencies by running:

cd ios to navigate to the

  • bundle install # to install Bundler If needed: install a Ruby Version Manager and update the Ruby version
  • bundle exec pod install # to install the iOS dependencies. 注意执行这一步需要梯子,而且需要反复尝试,因为可能网络超时

参考

android 环境

  • jdk 需要 jdk11 自行安装

这里给出 mac 下 jdk 多版本切换的方法,假如你的 mac 同时安装了 jdk8,jdk11, jdk17 ,假设已经安装完毕, 想用那个打开对应的注释即可。

查看所有的 jdk 安装路径
/usr/libexec/java_home -V

# java 多版本管理  https://www.cnblogs.com/yyxianren/p/14435118.html
#java
export JAVA_8_HOME="/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home"
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
export ORACLE_JAVA_8_HOME="/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home"
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
alias ojdk8='export JAVA_HOME=$JAVA_8_HOME'
export JAVA_11_HOME="/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home"
# alias jdk11='export JAVA_HOME=$JAVA_11_HOME'

export JAVA_17_HOME="/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home"
alias jdk11='export JAVA_HOME=$JAVA_17_HOME'

# 默认使用jdk8
# export JAVA_HOME=$JAVA_8_HOME
# export JAVA_HOME=$ORACLE_JAVA_8_HOME
export JAVA_HOME=$JAVA_11_HOME
# export JAVA_HOME=$JAVA_17_HOME
# java END%

安装 android studio

在这个网址下载安装,没啥好说的, developer.android.google.cn/studio/

将一些工具添加到环境变量里面,我使用的 zsh,编辑 ~/.zshrc 在最后添加

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

在 react-native 项目的 android 目录里的 build.gradle 下,可能会有一些速度提升,写到这里我的硬盘快满了,我决定先不探索了,稍后在更新,

repositories {
    <!-- # 新增这一行 -->
    maven{ url 'https://maven.aliyun.com/nexus/content/groups/public'}
    google()
    mavenCentral()
}

参考

  1. zhuanlan.zhihu.com/p/183958705
  2. blog.csdn.net/wqs1028/art…
  3. zhuanlan.zhihu.com/p/147821945