我有7个设备插入我的开发机器。我怎样才能安装apk到多个连接的设备?
通常我做adb install <path to apk>
,可以安装到一个单一的设备。
现在我想安装我的所有7个连接的设备上的我的apk。我怎样才能在一个命令中做到这一点?我想运行一个脚本也许。
我有7个设备插入我的开发机器。我怎样才能安装apk到多个连接的设备?
通常我做adb install <path to apk>
,可以安装到一个单一的设备。
现在我想安装我的所有7个连接的设备上的我的apk。我怎样才能在一个命令中做到这一点?我想运行一个脚本也许。
您可以使用adb devices
获取连接设备的列表,然后针对列出的每个设备运行adb -s DEVICE_SERIAL_NUM install...
。
喜欢的东西(庆典):
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 ...
谢谢!不幸的是,我无法让脚本运行。我不是shell脚本专家。我得到错误:'xargs:非法选项 - 我 用法:xargs [-Oopt] [-E eofstr] [-I replstr [-R替换]] [-J replstr] [-l编号] [-n编号[-x]] [-P maxprocs] [-s大小] [实用程序[参数...]]' – 2011-12-22 23:37:40
尝试用'-IX'替换'-iX' – kichik 2011-12-22 23:40:29
没有错误,但没有任何反应后,我执行line – 2011-12-23 02:42:28
使用Android Debug Bridge版本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
不确定它是否适用于早期版本。
下面的命令应该工作:
$ 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设备返回的设备列表中。使用tail -n +2从第二行开始,并使用-n -1结尾去除最后一个空行。通过使用默认制表符分隔符进行切分可以获得序列中的第一列。
xargs用于为每个串行运行adb命令。如果不重新安装,请删除-r选项。
这只在我从头部命令中删除了-1并用1代替后才起作用。此外,这只安装在第一个设备上,并非全部。如果我不在head命令中用1替换-1,则会得到一个./adb设备| tail -n +2 | head -n -1 head:非法行数 - -1 – Siddharth 2012-08-24 09:41:45
** head:非法行数 - -1 ** – 2016-10-06 19:51:29
下面是kichik的响应定制功能一行命令(谢谢!):
adb devices | tail -n +2 | cut -sf 1 | xargs -iX adb -s X install -r *.apk
但是,如果你碰巧使用Maven这是更简单:
mvn android:deploy
我该如何设置Android? – 2016-10-06 19:51:06
不适合我。输出:xargs:adb:由信号终止13 – 2017-06-08 14:19:42
另一个短选项..我偶然发现了这个页面,要知道-s $SERIAL
必须在实际的adb命令之前出现!感谢stackoverflow!
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s $SERIAL install -r /path/to/product.apk`;
done
其他答案是非常有用的,但没有完全做我所需要的。我想我会发布我的解决方案(一个shell脚本),以防其他读者提供更多的清晰度。它安装多个apks和任何mp4s
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"
谢谢所有其他答案让我到这一点。
完美的,只要我们可以将它与genymotion设备一起使用,通过tcpip连接...没有办法用-s – 2013-11-26 21:52:49
@Jose_GD来引用它们为什么不呢?看到我的答案,我成功地使用它 – Drew 2015-02-04 13:01:21
@Drew抱歉,你是对的。后来我了解到-s ip_address是可能的。 – 2015-03-16 21:24:00
广义的解决方案在所有设备上运行任何命令:
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do echo adb -s $SERIAL [email protected];
done
把它放在像“adb_all”一些脚本,并使用相同的方式,亚行单个设备。
另一个还好我发现的是叉后台进程的每个命令,并等待其完成:
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do adb -s $SERIAL [email protected] &
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
我很喜欢这个想法。在我的'〜/ bin'文件夹中很好用。 – 2013-10-06 20:50:33
使用此命令行实用程序:adb-foreach
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:标准输出和STDERR被压制。您不会看到任何“adb install”操作结果。我猜,这可能会有所改进,如果你真的需要
注意2:你也可以通过提供参数而不是硬编码的路径和活动名称来改善脚本。
这样你:
我喜欢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
我的版本做同样的事情,除了:
ŧ这里有几种方法可以改进,但我对此很满意。
根据此脚本,我为Unity应用程序构建了一个版本http://www.benoitfreslon.com/fr/2017/08/unity-install-and-run-an-apk-on-all-connected-devices-with -a-的bash脚本上-OS-X / – 2017-08-28 10:34:28
从这里起源: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设备;使用此
的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
此命令可以完美运行 adb devices | awk 'NR>1{print $1}' | xargs -n1 -I% adb -s % install foo.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
uninstallapp.rb https://gist.github.com/XinyueZ/2d61133b6acbde19f3c5 installapk.rb https://gist.github.com/XinyueZ/2128a11e174141908728 – TeeTracker 2015-12-07 09:27:46