新建文件 setup.bat 页面操作 注:中文乱码请使用ANSI编码格式
@echo off title apk助手 :menu cls color 0A echo. echo ============================== echo 请选择要进行的操作,然后按回车 echo ============================== echo. echo 1.安装 echo. echo 2.卸载 echo. echo 3.打印日志 echo. echo 4.截图保存(保存到脚本当前文件夹下screencap文件夹中) echo. echo 5.推送文件(推送到手机内存卡根目录) echo. echo Q.退出 echo. echo M.菜单 echo. echo 注:可多设备批量操作 echo. :cho set choice= set /p choice= 请选择操作类型: IF NOT "%choice%"=="" SET choice=%choice:~0,1% if /i "%choice%"=="Q" goto exit if /i "%choice%"=="M" goto menu if /i "%choice%"=="1" goto input if /i "%choice%"=="2" goto input if /i "%choice%"=="3" goto input if /i "%choice%"=="4" goto handler if /i "%choice%"=="5" goto input echo 选择无效,请重新输入 echo. goto cho :input echo. set input= if /i "%choice%"=="1" set /p input= 请输入apk文件路径: if /i "%choice%"=="2" set /p input= 请输入包名: if /i "%choice%"=="3" set /p input= 请输入包名: if /i "%choice%"=="5" set /p input= 请输入文件路径: if /i "%input%"=="Q" goto exit if /i "%input%"=="M" goto menu IF NOT "%input%"=="" goto handler echo 无效输入,请重新输入 goto input :handler call :getdevices if /i "%choice%"=="1" echo 开始安装 if /i "%choice%"=="2" echo 开始卸载 if /i "%choice%"=="3" echo 开始获取日志 if /i "%choice%"=="4" echo 开始捕获屏幕 if /i "%choice%"=="5" echo 开始推送文件 for /f "skip=1 tokens=1 delims= " %%i in (devices.txt) do (start adb_command %choice% %%i %input%) goto end :getdevices echo. echo ------------------------start--------------------------- echo 获取设备列表 adb devices > devices.txt type devices.txt goto :eof :end del devices.txt echo ------------------------end---------------------------- pause goto menu :exit exit新建文件adb_command .bat和screencap文件夹,需和 setup.bat在相同文件夹下
if %1 == 1 goto install if %1 == 2 goto uninstall if %1 == 3 goto logcat if %1 == 4 goto screencap if %1 == 5 goto push :install adb -s %2 install -t -d -r %3 goto exit :uninstall adb -s %2 uninstall %3 goto exit :logcat for /f "tokens=2 delims= " %%i in ('adb -s %2 shell "ps | grep %3"') do set pid=%%i if "%pid%"=="" (echo 请启动%3应用后再按回车键重试) else (adb -s %2 shell logcat --pid %pid%) pause goto logcat :push for /f "delims==" %%i IN ('dir /b %3') do ( adb -s %2 push %3 /sdcard/%%i) goto exit :screencap set "$=%temp%\Spring" >%$% Echo WScript.Echo((new Date()).getTime()) cd /d %~dp0 for /f %%a in ('cscript -nologo -e:jscript %$%') do set timestamp=%%a adb shell screencap -p /sdcard/screencap_%timestamp%.png adb pull /sdcard/screencap_%timestamp%.png ./screencap/ :exit pause exit新建文件shell_install.sh
#!/bin/bash echo "开始安装" $1 adb devices > devices.txt echo "读取设备" line_num=0 while read -r line do if [ $line_num != 0 ] && [ -n "$line" ]; then dev=`echo $line | cut -d " " -f 1` echo "开始并行安装" $dev start adb_install.sh $dev $1 fi let line_num++ done < devices.txt rm -f devices.txt新建文件adb_install.sh,需和 shell_install.sh在相同文件夹下
echo start install $2 to $1 adb -s $1 install -t -d -r $2参考 使用 adb 命令一次性为多个设备安装 apk:https://blog.csdn.net/yang786654260/article/details/51915511/