Mac 电脑安装 ADB 环境完整指南
Mac 电脑安装 ADB 环境完整指南
Mac 电脑安装 ADB 环境完整指南
ADB(Android Debug Bridge)是 Android 开发的核心工具,用于与 Android 设备通信。在 Mac 上安装 ADB 环境有以下几种方法:
🍺 方法一:使用 Homebrew(推荐)
1. 安装 Homebrew(如果尚未安装)
/bin/bash -c"$(curl-fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"2. 安装 Android Platform Tools
brew install android-platform-tools 3. 验证安装
adb version # 应显示:Android Debug Bridge version x.x.x📦 方法二:手动安装
1. 下载 Android SDK Platform Tools
访问官方下载页面:
https://developer.android.com/studio/releases/platform-tools
选择 Mac 版本下载
2. 解压并移动到合适位置
unzip platform-tools-*.zip sudomv platform-tools /usr/local/share/ 3. 添加到环境变量
# 编辑配置文件(根据你的 shell 选择)nano ~/.zshrc # 或 ~/.bash_profile# 添加以下行exportPATH=$PATH:/usr/local/share/platform-tools # 保存后生效source ~/.zshrc 4. 验证安装
adb --version🔧 配置 USB 调试
1. 在 Android 设备上
- 进入 设置 > 关于手机
- 连续点击 版本号 7 次启用开发者模式
- 返回设置 > 开发者选项
- 启用 USB 调试
2. 在 Mac 上连接设备
# 查看连接设备 adb devices # 如果显示 "unauthorized"# 在设备上确认授权提示🛠️ 常见问题解决
问题:设备未列出
# 1. 检查 USB 连接模式(选择文件传输)# 2. 重启 ADB 服务 adb kill-server adb start-server # 3. 检查 USB 驱动程序 lsusb # 查看设备是否识别问题:命令未找到
# 检查环境变量echo$PATH# 确认 platform-tools 路径正确ls /usr/local/share/platform-tools/adb 问题:权限不足
# 添加执行权限sudochmod +x /usr/local/share/platform-tools/adb sudochmod +x /usr/local/share/platform-tools/fastboot ⚙️ 进阶配置
1. 创建别名简化命令
# 编辑 ~/.zshrcaliasadbd="adb devices"aliasadbr="adb reboot"aliasadbs="adb shell"# 保存后生效source ~/.zshrc 2. 无线调试(免 USB)
# 1. 通过 USB 连接设备 adb tcpip 5555# 2. 查看设备 IP adb shell ip-f inet addr show wlan0 # 3. 断开 USB 连接 adb connect <设备IP>:5555 # 4. 验证连接 adb devices 3. 安装 ADB 图形界面工具
- Android File Transfer:文件管理
https://www.android.com/filetransfer/
Scrcpy:屏幕镜像和控制
brew install scrcpy 📱 常用 ADB 命令速查
| 命令 | 功能 |
|---|---|
adb devices | 列出连接设备 |
adb install app.apk | 安装应用 |
adb uninstall com.example | 卸载应用 |
adb logcat | 查看设备日志 |
adb shell | 进入设备终端 |
adb pull /sdcard/file.txt | 从设备复制文件 |
adb push file.txt /sdcard/ | 向设备发送文件 |
adb reboot | 重启设备 |
adb reboot bootloader | 进入 bootloader |
adb shell screencap /sdcard/screen.png | 截屏 |
adb shell screenrecord /sdcard/video.mp4 | 录屏 |
🔄 更新 ADB
# Homebrew 方式 brew upgrade android-platform-tools # 手动方式# 重新下载最新 platform-tools 覆盖旧文件📦 卸载 ADB
# Homebrew 方式 brew uninstall android-platform-tools # 手动方式sudorm-rf /usr/local/share/platform-tools # 并从环境变量中移除相关路径安装完成后,您就可以在 Mac 上使用 ADB 命令调试 Android 设备、安装应用、查看日志等。建议使用 Homebrew 方式安装,便于后续更新和管理。