adb批量安裝apk腳本

adb批量安裝apk腳本

bat版本

1. 批處理腳本

新建文件 index.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
2. adb命令腳本

新建文件adb_command .bat,需和 index.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())
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
3.使用說明
雙擊`index.dat`文件,根據提示操作
	
注:需要adb環境

shell版本

1. 批處理腳本

新建文件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
2. adb安裝腳本

新建文件adb_install.sh,需和 shell_install.sh在相同文件夾下

echo start install $2 to $1
adb -s $1 install -t -d -r $2
3.使用說明
	1、打開git-bash.exe命令行面板
	2、輸入命令:sh shell_install.sh "apk文件路徑"
	3、等待安裝結束

注:需要Git環境和adb環境

參考
使用 adb 命令一次性爲多個設備安裝 apk:https://blog.csdn.net/yang786654260/article/details/51915511/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章