一、准备工具
1. 使用bash作为SHELL
打开终端
(Terminal),输入下方命令,之后不再赘述。
$ chsh -s /bin/bash
- 检验
$ echo $SHELL
2. 安装Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 中国境内加速安装可参考:HomebrewCN
-
后续使用推荐换源,参考操作: Homebrew仓库URL源替换方法
-
若习惯图形化界面可安装Cakebrew:
brew install cakebrew
-
- 检验
$ brew -v
3. 安装Python3.6和Java8
$ brew update
$ brew install python@3.6
$ brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
此处安装Python3.6的目的是为了安装pip3.6,便于之后使用。
多版本Python管理参考:Mac安装指定Python版本和指定库版本并且随意切换版本
- 检验
$ python3 -V && java -version
4. 安装14版本Node
强烈建议避免安装15版本。
$ brew install node@14
- 此外,中国境内推荐安装cnpm(npm的中国镜像版,与npm通用)
$ npm install cnpm -g --registry=https://registry.npm.taobao.org
- 检验
$ node -v && npm -v
5. 安装Android Studio和Xcode
自行选择,自行安装。
- Android Studio: https://developer.android.com/studio
- 根据项目需要选择SDK版本
- Xcode:https://developer.apple.com/download/
- Mac平台可直接从App Store上获取
- 完成Xcode安装后,需额外安装命令行工具
$ xcode-select --install $ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer #可选项,指定Xcode版本,用于Mac上安装了多个Xcode的情况
二、安装软件、模块
1. 配置环境变量
(1) JAVA_HOME
$ echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.bash_profile
$ source ~/.bash_profile
- 检验
$ echo $JAVA_HOME
(2) ANDROID_HOME
$ echo 'export USER_HOME=$(eval echo ~$user)' >> ~/.bash_profile
$ echo 'export ANDROID_HOME=$USER_HOME/Library/Android/sdk' >> ~/.bash_profile
$ echo 'export PATH=$ANDROID_HOME/platform-tools:$PATH' >> ~/.bash_profile
$ echo 'export PATH=$ANDROID_HOME/platform-tools/bin:$PATH' >> ~/.bash_profile
$ echo 'export PATH=$ANDROID_HOME/tools:$PATH' >> ~/.bash_profile
$ echo 'export PATH=$ANDROID_HOME/tools/bin:$PATH' >> ~/.bash_profile
$ echo 'export BUILDTOOLS_VERSION=$(eval echo `ls $ANDROID_HOME/build-tools`)' >> ~/.bash_profile
$ echo 'export PATH=$ANDROID_HOME/build-tools/$BUILDTOOLS_VERSION:$PATH' >> ~/.bash_profile
$ echo 'export PATH=$ANDROID_HOME/build-tools/$BUILDTOOLS_VERSION/bin:$PATH' >> ~/.bash_profile
$ source ~/.bash_profile
- 检验
$ echo $ANDROID_HOME
2. 继续安装
此处省略检验步骤,有需要可自行检查软件或模块的安装情况。
(1) Homebrew安装部分
$ sudo chown -R $(whoami) /usr/local/share/man/man5 /usr/local/share/man/man7
$ sudo xcodebuild -license accept
$ brew install carthage libimobiledevice ios-deploy cmake wix/brew/applesimutils ios-webkit-debug-proxy gstreamer ifuse lyft/formulae/set-simulator-location
$ brew install --cask osxfuse
$ brew tap facebook/fb
$ brew install idb-companion
$ pip3.6 install fb-idb
(2) npm安装部分(可选择用cnpm代替)
$ echo 'export OPENCV4NODEJS_DISABLE_AUTOBUILD=1' >> ~/.bash_profile
$ npm install -g appium wd appium-doctor webpack opencv4nodejs mjpeg-consumer ffmpeg
(3) 补充
下载并配置Bundletool
- 下载
bundletool.jar
:https://github.com/google/bundletool/releases- 加速镜像
- 将下载的文件重命名为
bundletool.jar
(注意“.jar”为后缀名) - 创建bundle-tool文件夹:
$ mkdir ~/Library/Android/sdk/bundle-tool
- 将
bundletool.jar
文件复制到上方的地址- 在
访达
中使用快捷键Command+Shift+G
- 输入
~/Library/Android/sdk/bundle-tool
后按回车键 - 复制文件
- 赋予文件可执行权限:
$ chmod +x bundletool.jar
- 在
- 添加环境变量
$ echo 'export PATH=$ANDROID_HOME/bundle-tool:$PATH' >> ~/.bash_profile $ source ~/.bash_profile
三、确认
$ appium-doctor
通过appium-doctor
可以确认所需软件、模块是否成功安装,以便作出针对性处理。
若一切顺利,则系统检测通过,并反馈Everything looks good, bye!
- 开启appium服务
$ appium
至此,Appium在macOS上的部署已完成,Congratulations! 🍺🍺🍺
参考资料:
[1]Krishna Chetan.Setup Appium on Mac OS for Android and iOS App Automation [EB/OL].https://krishnachetan.medium.com/setup-appium-on-mac-1e06f1178427, 2020-10-21/2021-4-7
[2]cuma2369.bash 获取环境变量_如何从Bash中的变量中的用户名获取用户的主目录? [EB/OL].https://blog.csdn.net/cuma2369/article/details/107668958, 2020-07-21/2021-4-7