winney

It is never too old to learn.

0%
winney

MacOs相关笔记

Mac系统——iOS环境

安装Homebrew

开源安装脚本库:https://gitee.com/cunkai/HomebrewCN

复制以下内容到你的终端:
intel芯片:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

M1芯片:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"

回车运行,按照提示运行下去就可以了

错误
做完上面的傻瓜式操作,理论上就OK了,但是我这边出现了安装完后用不了的错误

1
command not found : brew

经过检查后发现,是因为M1芯片的包安装位置不在是以前的/usr/local/
而是/opt/homebrew,所以要将配置文件里的环境变量改过来

1、首先进入根目录

1
$ cd ~

2、创建.zshrc文件

1
$ touch .zshrc

3、打开文件进行编辑

1
$ open -e .zshrc

4、如果有旧的环境就修改,没有就新增

1
2
export PATH=/opt/homebrew/bin:$PATH
export PATH=/opt/homebrew/sbin:$PATH

5、保存
使用command + s
6、生效环境变量

1
$ source .zshrc

7、测试

1
$ brew -v

原文链接:MacOs M1安装Homebrew 在国内最简单方法——使用这个安装成功

Homebrew国内如何自动安装(国内地址)(Mac & Linux)

旧文章:macOS安装Homebrew太慢,换用清华镜像

1
2
3
git config --global --add safe.directory /opt/homebrew/Homebrew/Library/Taps/homebrew/homebrew-core

git config --global --add safe.directory /opt/homebrew/Homebrew/Library/Taps/homebrew/homebrew-cask
查看镜像
1
cd "$(brew --repo)" && git remote -v

安装watchman

1
brew install watchman
报错信息
1
2
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

解决:

1
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE

参考:Mac系列之:Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW

查看版本

1
watchman -v

安装cocoapods

1
brew install cocoapods

镜像地址

1
https://mirrors.tuna.tsinghua.edu.cn
1
npm config set registry 镜像地址
1
2
3
4
5
6
7
8
9
10
npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - https://registry.npmmirror.com
edunpm - http://registry.enpmjs.org/
eu ----- http://registry.npmjs.eu/
au ----- http://registry.npmjs.org.au/
sl ----- http://npm.strongloop.com/
nj ----- https://registry.nodejitsu.com/
pt ----- http://registry.npmjs.pt/

切换回淘宝镜像

1
npm config set registry https://registry.npmmirror.com/

先用淘宝镜像安装项目,

1
npx react-native init AwesomeProject

安装不了cocoapods

切换到https://registry.npmmirror.com/

切换到项目目录

1
cd AwesomeProject

再安装cocoapods

1
npm i cocoapods

报错信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ react-native run-ios
info Found Xcode project "AwesomeProject.xcodeproj"
info Building (using "xcodebuild -project AwesomeProject.xcodeproj -configuration Debug -scheme AwesomeProject -destination id=A7F04948-7FA8-45D1-B4A6-C26B21B6548A")
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening AwesomeProject.xcodeproj.
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project AwesomeProject.xcodeproj -configuration Debug -scheme AwesomeProject -destination id=A7F04948-7FA8-45D1-B4A6-C26B21B6548A

User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES

Prepare packages

Computing target dependency graph and provisioning inputs

Create build description
Build description signature: bf2f29ad51ca6266b44cbb8d643576b3
Build description path: /Users/yangyanyi/Library/Developer/Xcode/DerivedData/AwesomeProject-fgqiuteczcwroxgbdakmwcrknckt/Build/Intermediates.noindex/XCBuildData/bf2f29ad51ca6266b44cbb8d643576b3-desc.xcbuild

note: Building targets in dependency order
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
warning: Unable to read contents of XCFileList '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Unable to read contents of XCFileList '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-input-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-input-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase '[CP] Copy Pods Resources' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase '[CP] Embed Pods Frameworks' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase 'Bundle React Native code and images' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase 'Start Packager' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')

** BUILD FAILED **


info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

参考:Fresh react-native (0.66) app does not build on XCode 13, iOS 11.6: compiler error on SysUio.o

参考:error Failed to build iOS project. We ran “xcodebuild” command but it exited with error code 65. i can not Run my Project

原因可能是没有安装cocoapods成功

1
cd ios 
1
pod install

然后报错信息:

1
2
3
4
5
[!] Error installing CocoaAsyncSocket
[!] /usr/local/bin/git clone https://github.com/robbiehanson/CocoaAsyncSocket.git /var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-8728-969mqt --template= --single-branch --depth 1 --branch 7.6.5

Cloning into '/var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-8728-969mqt'...
fatal: unable to access 'https://github.com/robbiehanson/CocoaAsyncSocket.git/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

解决:

(可能也不需要做下面这个设置,每次报以上错误的时候,一直pod install,直到安装成功)

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

参考:SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443

hermes-engine的安装问题

报错信息:

1
2
3
4
5
6
7
8
[!] Error installing hermes-engine
[!] /usr/bin/curl -f -L -o /var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-67147-8lkp1c/file.tgz https://github.com/facebook/react-native/releases/download/v0.70.1/hermes-runtime-darwin-v0.70.1.tar.gz --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.11.3 cocoapods-downloader/1.5.1'

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 496M 0 1343k 0 0 1299 0 4d 15h 0:17:38 4d 14h 894
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)

这个问题折腾了好久好久好久好久……

解决方案:
  1. 打开一个终端,先执行
1
2
export http_proxy='your.host:port' //your.host:port我的是127.0.0.1:1087
export https_proxy='your.host:port' your.host:port我的是127.0.0.1:1087
  1. 这个终端界面转到项目目录下,再执行pod install –verbose
1
pod install --verbose

在安装命令添加参数--verbose看打印详细信息

参考:Cocoapods安装私有库问题

安装完成

然后自动执行Generating Pods project

然后自动执行Integrating client project

1
2
3
4
5
6
7
8
9
10
11
[!] Please close any current Xcode sessions and use `myapp.xcworkspace` for this project from now on.

Integrating target `Pods-myapp` (`myapp.xcodeproj` project)

Integrating target `Pods-myapp-myappTests` (`myapp.xcodeproj` project)
- Running post integrate hooks
- Writing Lockfile in `Podfile.lock`
- Writing Manifest in `Pods/Manifest.lock`
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update

-> Pod installation complete! There are 59 dependencies from the Podfile and 49 total pods installed.

根据终端提示,如果想要使用刚添加的第三方库,必须打开MyApp.xcworkspace,而非之前的MyApp.xcodeProj

CocoaPods的安装与使用

运行项目
1
2
3
yarn ios 

yarn react-native run-ios
1
echo insecure >> ~/.curlrc然后 pod install
1
2
3
4
5
6
7
解决办法:
1.删除项目依赖包以及 yarn 缓存
rm -rf node_modules && yarn cache clean
2.重新装包
yarn install
3.清除 React-Native 缓存
rm -rf ~/.rncache

如果iOS使用的是Mac M1的架构,可能还会遇到Cocoapods 的一些兼容问题。如果在安装 pods依赖时出现问题,可以尝试运行下面的命令:

1
2
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install

详解React Native项目中启用Hermes引擎

解决 React-Native mac 运行报错 error Failed to build iOS project. We ran “xcodebuild” command but it exite

s

更新到最新版本RN 0.64.0后,React本机应用程序将无法运行

Installing React Native with Mapbox Navigation in iOS

参考:[!] Error installing Fabric. /usr/bin/curl -f -L -o /var/folders

参考:【解决】[!] Error installing Fabric. [!]/usr/bin/curl -f -L -o /var/folders

Pod Error installing Bugly

pod install 报错 :error installing AMapFoundation ,iOS 大佬们来看一下

Failed to build iOS project. We ran “xcodebuild” command but it exited with error code 65

镜像切换

Mac全自动安装brew一键配置国内镜像源

Mac HomeBrew国内镜像安装方法

科学上网

淘宝镜像:https://mirrors.aliyun.com/homebrew/?spm=a2c6h.13651104.0.0.1fc17608pdL2JD

Mac系统下——Android 环境

Java Development Kit

1
2
brew tap homebrew/cask-versions
brew install --cask zulu11

React Native 需要 Java Development Kit [JDK] 11。你可以在命令行中输入 javac -version(请注意是 javac,不是 java)来查看你当前安装的 JDK 版本

3. 配置 ANDROID_SDK_ROOT 环境变量

React Native 需要通过环境变量来了解你的 Android SDK 装在什么路径,从而正常进行编译。

具体的做法是把下面的命令加入到 shell 的配置文件中。如果你的 shell 是 zsh,则配置文件为~/.zshrc,如果是 bash 则为~/.bash_profile(可以使用echo $0命令查看你所使用的 shell。):

1
2
3
4
5
6
# 如果你不是通过Android Studio安装的sdk,则其路径可能不同,请自行确定清楚
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/tools
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools

译注:~表示用户目录,即/Users/你的用户名/,而小数点开头的文件在 Finder 中是隐藏的,并且这个文件有可能并不存在。可在终端下使用vi ~/.zshrc命令创建或编辑。如不熟悉 vi 操作,请点击这里学习。

使用source $HOME/.zshrc命令来使环境变量设置立即生效(否则重启后才生效)。可以使用echo $ANDROID_SDK_ROOT检查此变量是否已正确设置。

请确保你正确指定了 Android SDK 路径。你可以在 Android Studio 的”Preferences”菜单中查看 SDK 的真实路径,具体是Appearance & BehaviorSystem SettingsAndroid SDK