ADB Installation and Setup - langningchen/miniapp GitHub Wiki
本指南帮助您安装和配置 Android Debug Bridge (ADB) 工具,用于与有道词典笔进行通信和调试。
ADB (Android Debug Bridge) 是 Android 开发工具包的一部分,它允许您:
- 与 Android 设备通信
- 安装和卸载应用程序
- 传输文件
- 执行 shell 命令
- 调试应用程序
方法一:使用包管理器安装(推荐)
# 更新包列表
sudo apt update
# 安装 ADB 工具
sudo apt install -y adb
# 验证安装
adb version
方法二:安装完整的 Android SDK Platform Tools
# 创建下载目录
mkdir -p ~/android-sdk/platform-tools
cd ~/android-sdk/platform-tools
# 下载 Platform Tools
wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
# 解压
unzip platform-tools-latest-linux.zip
# 添加到 PATH
echo 'export PATH="$HOME/android-sdk/platform-tools/platform-tools:$PATH"' >> ~/.bashrc
source ~/.bashrc
# 验证安装
adb version
方法一:下载官方工具包
- 访问 Android 开发者网站
- 下载 "SDK Platform Tools for Windows"
- 解压到合适的目录(如
C:\adb\
) - 将目录添加到系统 PATH:
- 右键 "此电脑" → "属性"
- 点击 "高级系统设置"
- 点击 "环境变量"
- 在系统变量中找到 "Path",点击 "编辑"
- 添加 ADB 目录路径
方法二:使用 Chocolatey
# 安装 Chocolatey (如果还没有)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# 使用 Chocolatey 安装 ADB
choco install adb
在有道词典笔上启用开发者选项和 USB 调试:
- 进入设置:在词典笔上找到设置应用
- 关于设备:找到设备信息或关于设备选项
- 多次点击版本号:连续点击版本号 7 次,直到出现"您现在处于开发者模式"
-
启用 USB 调试:
- 返回设置主界面
- 找到"开发者选项"
- 启用"USB 调试"
- 启用"USB 调试(安全设置)"(如果有)
为了让普通用户能够访问 USB 设备:
# 创建 udev 规则文件
sudo nano /etc/udev/rules.d/51-android.rules
# 添加以下内容(根据您的设备调整 vendor ID)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666", GROUP="plugdev"
# 设置文件权限
sudo chmod a+r /etc/udev/rules.d/51-android.rules
# 重启 udev 服务
sudo service udev restart
# 将当前用户添加到 plugdev 组
sudo usermod -a -G plugdev $USER
# 注销并重新登录,或者运行:
newgrp plugdev
# 启动 ADB 守护进程
adb start-server
# 检查 ADB 状态
adb devices
-
使用 USB 线连接:
- 将有道词典笔用 USB 线连接到计算机
- 确保使用数据线,而不是仅充电线
-
设备授权:
# 检查设备连接 adb devices
如果是第一次连接,词典笔上会弹出授权对话框:
- 勾选"总是允许使用这台计算机进行调试"
- 点击"确定"
-
验证连接:
# 再次检查设备 adb devices # 应该显示类似: # List of devices attached # ABC123DEF456 device
如果支持网络 ADB:
# 通过 USB 连接后,启用网络 ADB
adb tcpip 5555
# 断开 USB,通过网络连接(替换为设备 IP)
adb connect 192.168.1.100:5555
# 验证连接
adb devices
# 查看设备信息
adb shell getprop ro.product.model
adb shell getprop ro.build.version.release
# 查看设备存储
adb shell df -h
# 查看正在运行的进程
adb shell ps | head -10
# 列出设备文件
adb shell ls /sdcard/
# 创建测试文件
echo "Hello from computer" > test.txt
# 推送文件到设备
adb push test.txt /sdcard/
# 从设备拉取文件
adb pull /sdcard/test.txt test_from_device.txt
# 查看文件内容
cat test_from_device.txt
# 清理测试文件
rm test.txt test_from_device.txt
adb shell rm /sdcard/test.txt
# 列出连接的设备
adb devices
# 重启设备
adb reboot
# 重启到恢复模式
adb reboot recovery
# 重启到下载模式
adb reboot download
# 推送文件到设备
adb push local_file.txt /sdcard/remote_file.txt
# 从设备拉取文件
adb pull /sdcard/remote_file.txt local_file.txt
# 推送整个目录
adb push local_directory/ /sdcard/remote_directory/
# 安装 APK
adb install app.apk
# 卸载应用
adb uninstall com.package.name
# 列出已安装的包
adb shell pm list packages
# 启动应用
adb shell am start -n com.package.name/.MainActivity
# 进入设备 shell
adb shell
# 执行单个命令
adb shell "ls -la /sdcard/"
# 查看日志
adb logcat
# 清除日志
adb logcat -c
根据项目 README,您需要获取设备版本信息:
# 进入设备 shell
adb shell
# 在设备上运行版本信息脚本
curl -k -s https://raw.githubusercontent.com/langningchen/miniapp/refs/heads/main/tools/getVersionInfo.sh | bash
# 退出设备 shell
exit
# 拉取生成的版本信息文件
adb pull /userdisk/Favorite/versionInfo.tar.gz ./versionInfo.tar.gz
编译完成后安装应用:
# 推送编译好的 miniapp 到设备
adb push miniapp.amr /userdisk/Favorite/miniapp.amr
# 进入设备 shell 并安装
adb shell
miniapp_cli install /userdisk/Favorite/miniapp.amr
exit
运行以下命令确保 ADB 配置正确:
# 检查 ADB 版本
adb version
# 检查设备连接
adb devices
# 测试设备通信
adb shell echo "ADB is working!"
# 检查设备基本信息
adb shell getprop | grep -E "(model|version|brand)"
ADB 配置完成后,请继续:
- CMake 和编译工具链 - 安装 C++ 编译工具
- 设备连接和调试 - 深入了解设备调试
解决方案:
# 检查是否正确安装
which adb
# 重新安装
sudo apt install adb
# 或添加到 PATH
echo 'export PATH="$HOME/android-sdk/platform-tools:$PATH"' >> ~/.bashrc
source ~/.bashrc
解决方案:
# 确保用户在 plugdev 组中
sudo usermod -a -G plugdev $USER
# 重新登录或运行
newgrp plugdev
# 重启 ADB 服务
adb kill-server
adb start-server
解决方案:
- 检查设备上是否弹出授权对话框
- 确保勾选"总是允许"
- 如果没有弹出,运行:
adb kill-server
adb start-server
adb devices
解决方案:
# 重启 ADB 连接
adb disconnect
adb connect [device_ip] # 如果使用网络连接
# 或重新插拔 USB 线
adb kill-server
adb start-server
解决方案:
- WSL2 需要额外配置来访问 USB 设备
- 可以在 Windows 中运行 ADB,然后在 WSL2 中使用网络连接
- 或安装 USBIPD 工具来共享 USB 设备
# 在 Windows PowerShell 中
winget install usbipd
# 查看 USB 设备
usbipd wsl list
# 绑定设备到 WSL
usbipd wsl attach --busid <busid>