c4rt1y

Mac M1 平台搭建 appium 环境

0x01 介绍

近期想捣鼓自动化,因而安装了下appium。
设备系统: mac M1 Big Sur 版本 11.5.2

需要安装如下软件:
1、brew
2、node
3、appium
4、appium-doctor
5、carthage
6、xcode
7、java
8、android sdk

0x02 行动

1、安装brew
![参考此文章](/_site/2019/08-06-install-jupyter-notebook-in-centos-server/login-jupyter-lab.png)

2、安装node
下载链接:http://nodejs.cn/download/
直接下载了pkg文件,进行安装

3、安装appium
sudo npm install -g appium --unsafe-perm=true --allow-root
npm config set registry http://registry.npm.taobao.org/
sudo npm install -g appium --chromedriver-skip-install

或者可以通过dmg安装
https://github.com/appium/appium-desktop/releases

4、安装appium-doctor
sudo npm install -g appium-doctor


5、安装carthage
brew install carthage

6、安装xcode
#登陆app store,搜索xcode,下载,很大,需要很久时间
#默认的xcode-select --print-path 地址存在问题,需要修改为
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/

然后输出version版本看是否是正常
xcodebuild -version

当xcode安装完毕,需要运行一下,主要是为了授权,顺便看下Xcode-->Preferences-->Locations-->Command Line Tools是否和xcode-select --print-path保持一致即可

7、安装java
下载链接:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
选择mac版本,然后下载dmg文件安装(需要登陆)
安装完毕,执行java -version进行确认是否ok
写入环境变量
echo "export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home" >> ~/.zshrc

8、安装android sdk
下载链接:https://developer.android.com/studio
下载后安装,选择custom模式安装,调用自己的java环境,然后全部继续next 和finish即可
写入环境变量
echo "export ANDROID_HOME=${HOME}/Library/Android/sdk" >> ~/.zshrc
echo "export PATH=${PATH}:${ANDROID_HOME}/platform-tools" >> ~/.zshrc
echo "export PATH=${PATH}:${ANDROID_HOME}/tools" >> ~/.zshrc
echo "export PATH=${PATH}:${ANDROID_HOME}/platforms" >> ~/.zshrc
echo "export PATH=${PATH}:${ANDROID_HOME}/build-tools/31.0.0" >> ~/.zshrc

#整体环境就搭建ok,运行【看是否会有报错】
appium-doctor 
info AppiumDoctor Appium Doctor v.1.16.0
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor  ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor  ✔ Node version is 14.18.0
info AppiumDoctor  ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor  ✔ Xcode Command Line Tools are installed in: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor  ✔ DevToolsSecurity is enabled.
info AppiumDoctor  ✔ The Authorization DB is set up properly.
info AppiumDoctor  ✔ Carthage was found at: /opt/homebrew/bin/carthage. Installed version is: 0.38.0
info AppiumDoctor  ✔ HOME is set to: /Users/coco
info AppiumDoctor  ✔ ANDROID_HOME is set to: /Users/coco/Library/Android/sdk
info AppiumDoctor  ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home
info AppiumDoctor    Checking adb, android, emulator
info AppiumDoctor      'adb' is in /Users/coco/Library/Android/sdk/platform-tools/adb
info AppiumDoctor      'android' is in /Users/coco/Library/Android/sdk/tools/android
info AppiumDoctor      'emulator' is in /Users/coco/Library/Android/sdk/emulator/emulator
info AppiumDoctor  ✔ adb, android, emulator exist: /Users/coco/Library/Android/sdk
info AppiumDoctor  ✔ 'bin' subfolder exists under '/Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home'
info AppiumDoctor ### Diagnostic for necessary dependencies completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
WARN AppiumDoctor  ✖ opencv4nodejs cannot be found.
WARN AppiumDoctor  ✖ ffmpeg cannot be found
WARN AppiumDoctor  ✖ mjpeg-consumer cannot be found.
WARN AppiumDoctor  ✖ set-simulator-location is not installed
WARN AppiumDoctor  ✖ idb and idb_companion are not installed
WARN AppiumDoctor  ✖ applesimutils cannot be found
WARN AppiumDoctor  ✖ ios-deploy cannot be found
WARN AppiumDoctor  ✖ bundletool.jar cannot be found
WARN AppiumDoctor  ✖ gst-launch-1.0 and/or gst-inspect-1.0 cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 9 fixes possible. ###
info AppiumDoctor
info AppiumDoctor ### Optional Manual Fixes ###
info AppiumDoctor The configuration can install optionally. Please do the following manually:
WARN AppiumDoctor  ➜ Why opencv4nodejs is needed and how to install it: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md
WARN AppiumDoctor  ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it
WARN AppiumDoctor  ➜ mjpeg-consumer module is required to use MJPEG-over-HTTP features. Please install it with 'npm i -g mjpeg-consumer'.
WARN AppiumDoctor  ➜ set-simulator-location is needed to set location for Simulator. Please read https://github.com/lyft/set-simulator-location to install it
WARN AppiumDoctor  ➜ Why idb is needed and how to install it: https://github.com/appium/appium-idb
WARN AppiumDoctor  ➜ Why applesimutils is needed and how to install it: http://appium.io/docs/en/drivers/ios-xcuitest/
WARN AppiumDoctor  ➜ ios-deploy is used as a fallback command to install iOS applications to real device. Please read https://github.com/ios-control/ios-deploy/ to install it
WARN AppiumDoctor  ➜ bundletool.jar is used to handle Android App Bundle. Please read http://appium.io/docs/en/writing-running-appium/android/android-appbundle/ to install it
WARN AppiumDoctor  ➜ gst-launch-1.0 and gst-inspect-1.0 are used to stream the screen of the device under test. Please read https://appium.io/docs/en/writing-running-appium/android/android-screen-streaming/ to install them and for more details

0x03 错误查纠

问题1:Carthage was NOT found!
由于第五步操作没做,请看第二章节第五步

Error running xcrun simctl
由于第六步操作没做,请看第二章节第六步

Cannot check $JAVA_HOME requirements since the environment variable itself is not set
由于第七步操作没做,请看第二章节第七步

JAVA_HOME environment variable is NOT set!
由于第七步操作没做,请看第二章节第七步

adb, android, emulator could not be found because ANDROID_HOME or ANDROID_SDK_ROOT is NOT set!
由于第八步操作没做,请看第二章节第八步

ANDROID_HOME environment variable is NOT set!
由于第八步操作没做,请看第二章节第八步

0x03 资料来源

https://blog.csdn.net/qq_37733396/article/details/120470092
https://www.icode9.com/content-4-1137222.html
https://www.jianshu.com/p/e9706a2ebdbb
https://www.jianshu.com/p/e828afede8cc
GoTop