blog/source/_posts/react-native-traps.md

41 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: React Native踩坑集锦
tags:
- 前端
- Javascript
- Typescript
- React Native
categories:
- - 前端
- React Native
keywords: 'react,react native,typescript,javascript,cocoapods'
date: 2021-06-30 06:32:14
---
React Native是一个利用前端技术实现的移动端框架所以在开发环境构建和应用开发过程中常常需要同时用到前端和移动端的技术这也就导致了React Native在使用的时候也会同时踩前端和移动端的两重坑。这里对已经踩过的坑做一个记录方便再碰上以后能跳过去。<!-- more -->
## 更换CocoaPods的镜像
在使用`react-native-cli`构建React Native应用的时候会使用到用于iOS的CocoaPods框架这个框架在不使用镜像的时候常常会导致应用的iOS部分创建失败。要解决这个问题可以将CocoaPods的镜像改为清华Tuna镜像。
!!! caution ""
一般CocoaPods出问题最常见的提示就是`[!] CocoaPods could not find compatible versions for pod`。
由于新版的React Native0.60以上版本使用的一般都是新版的CocoaPods所以这里不再记录对于旧版CocoaPods切换镜像的操作了。
要切换CocoaPods的镜像需要按顺序执行以下几条命令。
```bash
cd ~/.cocoapods/repos
pod repo remove master
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
```
然后再回到应用项目目录中的`ios`目录中执行`pod install --repo-update`。执行结束后,再将项目中的`Podfile`顶部添加以下一行内容。
```bash
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
```
即可完成CocoaPods镜像的切换。