如何 adb 将 apk 安装到多个连接的设备?
我的开发机器上插入了 7 个设备。
通常我会执行 adb install
并且可以安装到单个设备上。
现在我想在所有 7 个连接的设备上安装我的 apk。我怎样才能用一个命令来做到这一点?也许我想运行一个脚本。
I have 7 devices plugged into my development machine.
Normally I do adb install <path to apk>
and can install to just a single device.
Now I would like to install my apk on all of my 7 connected devices. How can I do this in a single command? I'd like to run a script perhaps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(21)
您可以使用
adb devices
获取已连接设备的列表,然后对列出的每个设备运行adb -s DEVICE_SERIAL_NUM install...
。像 (bash) 之类的东西:
评论表明这对于较新的版本可能会更好:
对于 Mac OSX(未在 Linux 上测试):
You can use
adb devices
to get a list of connected devices and then runadb -s DEVICE_SERIAL_NUM install...
for every device listed.Something like (bash):
Comments suggest this might work better for newer versions:
For Mac OSX(not tested on Linux):
其他答案非常有用,但并没有完全满足我的需要。我想我应该发布我的解决方案(一个 shell 脚本),以防它为其他读者提供更多清晰度。它会安装多个 apk 和任何 mp4
感谢您提供的所有其他答案让我走到这一步。
The other answers were very useful however didn't quite do what I needed. I thought I'd post my solution (a shell script) in case it provides more clarity for other readers. It installs multiple apks and any mp4s
Thank you for all the other answers that got me to this point.
这是根据 kichik 的回复定制的实用单行命令(谢谢!):
但如果你碰巧使用 Maven,那就更简单了:
Here's a functional one line command tailored from kichik's response (thanks!):
But if you happen to be using Maven it's even simpler:
另一个简短的选择...我偶然发现此页面,发现
-s $SERIAL
必须出现在实际的 adb 命令之前!感谢堆栈溢出!Another short option... I stumbled on this page to learn that the
-s $SERIAL
has to come before the actual adb command! Thanks stackoverflow!Dave Owens 在所有设备上运行任何命令的通用解决方案:
将其放入“adb_all”等脚本中,并使用与单个设备的 adb 相同的方式。
我发现的另一件好事是为每个命令分叉后台进程,并等待它们完成:
然后您可以轻松创建一个脚本来安装应用程序并启动活动
Generalized solution from Dave Owens to run any command on all devices:
Put it in some script like "adb_all" and use same way as adb for single device.
Another good thing i've found is to fork background processes for each command, and wait for their completion:
Then you can easily create a script to install app and start the activity
我喜欢 workingMatt 的脚本,但认为它可以改进一点,这是我的修改版本:
我的版本做了同样的事情,除了:
有几种方法仍然可以改进,但我对此非常满意。
I liked workingMatt's script but thought it could be improved a bit, here's my modified version:
My version does the same thing except:
There's a few ways it could still be improved but I'm quite happy with it.
以下命令应该有效:
adb devices 返回设备列表。使用 tail -n +2 从第二行开始,使用 head -n -1 删除末尾的最后一个空行。使用默认制表符分隔符进行管道传输可以得到第一列,即序列号。
xargs 用于为每个序列运行 adb 命令。如果不重新安装,请删除 -r 选项。
The following command should work:
adb devices returns the list of devices. Use tail -n +2 to start from the 2nd line and head -n -1 to remove the last blank line at the end. Piping through cut with the default tab delimiter gets us the first column which are the serials.
xargs is used to run the adb command for each serial. Remove the -r option if you are not re-installing.
使用这个脚本,你可以做到:
干净、简单。
With this script you can just do:
Clean, simple.
PowerShell 解决方案
将其放入您的配置文件 (
notepad $PROFILE
) 中,重新启动 shell,您可以使用以下命令调用安装:PowerShell solution
Put this in your profile file (
notepad $PROFILE
), restart your shell and you can invoke installations with :如果您不想使用未启用adb的设备;使用此
Mac/Linux
If you don't want use the devices that have not enabled adb; use this
Mac/Linux
使用此命令行实用程序:adb-foreach
Use this command-line utility: adb-foreach
这个命令完美运行
adb 设备 | awk 'NR>1{print $1}' | xargs -n1 -I% adb -s % 安装 foo.apk
This command works perfect
adb devices | awk 'NR>1{print $1}' | xargs -n1 -I% adb -s % install foo.apk
很简单,您可以创建一个 installapk.bat 文件,该文件可以将多个 apk 完成到多个连接设备的工作,使用 notepad++ 打开 installapk.bat 并复制粘贴此代码
well its simple you can create a installapk.bat file that can do the job for multiple apk to multiple connected devices open installapk.bat with notepad++ and copy paste this code
这是用于在所有连接的设备上安装和运行 apk 的 bash
使用
nick@nickolay:/home/workspace/MyProject$ > bash 路径/to/installAndRunApk.sh
installAndRunApk.sh
Here is bash for install and run apk on all connected devices
Using
nick@nickolay:/home/workspace/MyProject$ > bash path/to/installAndRunApk.sh
installAndRunApk.sh
我添加了@WorkingMatt 的答案,
我更新了他的答案,另外执行以下操作
I added to the answer from @WorkingMatt
I updated his answer to additionally do the following things
使用 Android Debug Bridge 版本 1.0.29,尝试这个 bash 脚本:
不确定它是否适用于早期版本。
With Android Debug Bridge version 1.0.29, try this bash script:
Not sure if it works with earlier versions.
关键是在单独的进程 (&) 中启动
adb
。我想出了以下脚本来同时在我的所有连接设备上启动安装,并最终在每个设备上启动已安装的应用程序:
注1: STDOUT 和 STDERR 被抑制。您不会看到任何“adb install”操作结果。我想,如果您确实需要
注意2:,这可能会得到改进,您还可以通过提供参数而不是硬编码的路径和活动名称来改进脚本。
这样您就可以:
The key is to launch
adb
in a separate process (&).I came up with the following script to simultaneously fire-off installation on all of the connected devices of mine and finally launch installed application on each of them:
Note 1: the STDOUT and STDERR are suppressed. You won't see any "adb install" operation result. This may be improved, I guess, if you really have to
Note 2: you could also improve script by providing args instead of hardcoded path and activity names.
That way you:
源自这里:将上一篇文章设为 Mass APK不使用 ADB Install-Multi 语法的安装程序
Originated from here: Make The Previous Post A Mass APK Installer That Does Not Uses ADB Install-Multi Syntax
由于我无法评论 @Tom 的答案,这对我在 OSX 10.13 上有效
(将小 i 更改为大 I)
Since I can't comment on the answer by @Tom, this worked for me on OSX 10.13
(Change the little i to a big I)
我想记录安装时发生的情况,也需要它稍微易于理解。最终结果是:
在 Linux 上进行了测试苹果
I was wanting to log what was happening whilst installing, also needed it to be slightly comprehendable. Ended up with:
Tested on Linux & Mac
-获取
.apk
文件夹中存储的所有apk
-在设备上安装和替换应用
-Get all the
apk
stored in.apk
folder-Install and replace app on devices