我有插到我的机器7个设备。
通常我做adb install <path to apk>
并且可以安装只是一个单一的设备。
现在,我想我所有的7点连接的设备上安装APK我。我怎样才能做到这一点在一个命令?我想也许是运行一个脚本。
您可以使用adb devices
获取连接的设备的清单,然后运行adb -s DEVICE_SERIAL_NUM install...
对列出的每个设备。
喜欢的东西(bash)的:
adb devices | tail -n +3 | cut -sf 1 -d " " | xargs -iX adb -s X install ...
评论认为这可能工作的新版本更好的:
adb devices | tail -n +2 | cut -sf 1 | xargs -iX adb -s X install ...
对于Mac OSX(在Linux上未测试):
adb devices | tail -n +2 | cut -sf 1 | xargs -I {} adb -s {} install ...
使用此命令行实用程序:adb-foreach
借助Android调试桥版本1.0.29,试试这个bash script:
APK=$1
if [ ! -f `which adb` ]; then
echo 'You need to install the Android SDK before running this script.';
exit;
fi
if [ ! $APK ]; then
echo 'Please provide an .apk file to install.'
else
for d in `adb devices | ack -o '^\S+\t'`; do
adb -s $d install $APK;
done
fi
不知道这是否与早期版本的作品。
PowerShell的解决方案
function global:adba() {
$deviceIds = iex "adb devices" | select -skip 1 | %{$_.Split([char]0x9)[0].Trim() } | where {$_ -ne "" }
foreach ($deviceId in $deviceIds) {
Echo ("--Executing on device " + $deviceId + ":---")
iex ("adb -s $deviceId " + $args)
}
}
把这个在您的配置文件(notepad $PROFILE
),重新启动您的外壳,你可以调用安装:
adba install yourApp.apk
关键是在一个独立的进程(&)启动adb
。
我用下面的脚本来了个全矿的连接设备,最后发动对他们每个人安装的应用程序同时火关安装:
#!/bin/sh
function install_job {
adb -s ${x[0]} install -r PATH_TO_YOUR_APK
adb -s ${x[0]} shell am start -n "com.example.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
}
#iterate over devices IP-addresses or serial numbers and start a job
while read LINE
do
eval x=($LINE)
install_job ${x[0]} > /dev/null 2>&1 &
done <<< "`adb devices | cut -sf 1`"
echo "WATING FOR INSTALLATION PROCESSES TO COMPLETE"
wait
echo "DONE INSTALLING"
注1:输出和错误被抑制。你不会看到任何“亚行安装”操作的结果。这可能会得到改善,我想,如果你真的要
注2:您还可以通过提供args来代替硬编码路径和活动名称改进脚本。
这样,你:
从这里起源:Make The Previous Post A Mass APK Installer That Does Not Uses ADB Install-Multi Syntax
@echo off :loop ::-------------------------- has argument ? if ["%~1"]==[""] ( echo done. goto end ) ::-------------------------- argument exist ? if not exist %~s1 ( echo error "%~1" does not exist in file-system. ) else ( echo "%~1" exist if exist %~s1\NUL ( echo "%~1" is a directory ) else ( echo "%~1" is a file! - time to install: call adb install %~s1 ) ) ::-------------------------- shift goto loop :end pause ::: ########################################################################## ::: ## ## ::: ## 0. run: adb devices - to start the deamon and list your device ## ::: ## ## ::: ## 1. drag&drop ANY amount of files (APK) over this batch files, ## ::: ## ## ::: ## - it will install them one by one. ## ::: ## - it just checks if file exists. ## ::: ## - it does not checks if it is a valid APK package ## ::: ## - it does not checks if package-already-installed ## ::: ## - if there is an error you can always press [CTRL]+[C] ## ::: ## to stop the script, and continue from the next one, ## ::: ## some other time. ## ::: ## - the file is copied as DOS's 8.3 naming to you ## ::: ## don't need to worry about wrapping file names or renaming ## ::: ## them, just drag&drop them over this batch. ## ::: ## ## ::: ## Elad Karako 1/1/2016 ## ::: ## http://icompile.eladkarako.com ## ::: ##########################################################################
这个命令可以完美运行adb devices | awk 'NR>1{print $1}' | xargs -n1 -I% adb -s % install foo.apk
既然不能由@汤姆的回答发表评论,这为我工作在OSX 10.13
adb devices | tail -n +2 | cut -sf 1 | xargs -IX adb -s X install -r path/to/apk.apk
(更改小我到大我)
以及它的简单,你可以创建一个installapk.bat文件,可以用记事本+ +的多个APK做的工作,以多种连接设备开放installapk.bat和复制粘贴此代码
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Facebook.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Instagram.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Messenger.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Outlook.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Viber.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r WhatsApp.apk
- 获得存储在apk
文件夹中所有.apk
- 安装和设备替代应用
getBuild() {
for entry in .apk/*
do
echo "$entry"
done
return "$entry"
}
newBuild="$(getBuild)"
adb devices | while read line
do
if [! "$line" = ""] && ['echo $line | awk "{print $2}"' = "device"]
then
device='echo $line | awk "{print $1}"'
echo "adb -s $device install -r $newbuild"
adb -s $device install -r $newbuild
fi
done
其他的答案是非常有用但是并没有完全做到我需要的。我想我会后我的解决方案(shell脚本)的情况下,它提供了更清晰的其他读者。它安装多个APK任何mp4文件
echo "Installatron"
for SERIAL in $(adb devices | tail -n +2 | cut -sf 1);
do
for APKLIST in $(ls *.apk);
do
echo "Installatroning $APKLIST on $SERIAL"
adb -s $SERIAL install $APKLIST
done
for MP4LIST in $(ls *.mp4);
do
echo "Installatroning $MP4LIST to $SERIAL"
adb -s $SERIAL push $MP4LIST sdcard/
done
done
echo "Installatron has left the building"
谢谢你的一切让我到这一点其他的答案。
下面是kichik的响应定制功能一行命令(谢谢!):
ADB设备|尾-n +2 |切-sf 1 | xargs的-ix ADB -s X安装-r * .apk文件
但是,如果你碰巧使用是Maven的是更简单:
MVN安卓:部署
另一个短选项...我无意中发现这个网页上得知-s $SERIAL
有来实际ADB命令之前!谢谢计算器!
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s $SERIAL install -r /path/to/product.apk`;
done
从戴夫·欧文斯广义的解决方案运行在所有设备上的任何命令:
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do echo adb -s $SERIAL $@;
done
把它像“adb_all”一些脚本,并使用相同的方式,亚行单个设备。
另一件好事我发现的是叉后台进程的每个命令,并等待其完成:
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do adb -s $SERIAL $@ &
done
for job in `jobs -p`
do wait $job
done
然后你就可以轻松地创建一个脚本来安装应用程序,并开始活动
./adb_all_fork install myApp.apk
./adb_all_fork shell am start -a android.intent.action.MAIN -n my.package.app/.MainActivity
我喜欢workingMatt's script但认为还可以提高一点,这是我修改后的版本:
#!/bin/bash
install_to_device(){
local prettyName=$(adb -s $1 shell getprop ro.product.model)
echo "Starting Installatroning on $prettyName"
for APKLIST in $(find . -name "*.apk" -not -name "*unaligned*");
do
echo "Installatroning $APKLIST on $prettyName"
adb -s $1 install -r $APKLIST
adb -s $1 shell am start -n com.foo.barr/.FirstActivity;
adb -s $1 shell input keyevent KEYCODE_WAKEUP
done
echo "Finished Installatroning on $prettyName"
}
echo "Installatron"
gradlew assembleProdDebug
for SERIAL in $(adb devices | tail -n +2 | cut -sf 1);
do
install_to_device $SERIAL&
done
我的版本做同样的事情,除了:
有几个方法可能仍有待提高,但我与它很高兴。
下面的命令应该工作:
$ adb devices | tail -n +2 | head -n -1 | cut -f 1 | xargs -I X adb -s X install -r path/to/your/package.apk
ADB设备返回的设备列表中。使用尾-n +2从2号线和头开始-n -1,除去在年底的最后一个空行。通过切断与默认选项卡分隔符管道获取我们的第一列这是连续剧。
xargs的用于运行对每个串行的ADB命令。删除-r选项,如果你不重新安装。
如果你不想使用尚未启用ADB设备;用这个
的Mac / Linux的
adb devices | grep device | grep -v devices | awk '{print$1}' | xargs -I {} adb -s {} install path/to/yourApp.apk
adb devices | grep device | grep -v devices | cut -sf 1 | xargs -I {} adb -s {} install path/to/yourApp.apk