如何 adb 将 apk 安装到多个连接的设备?

发布于 2024-12-22 08:50:31 字数 159 浏览 5 评论 0原文

我的开发机器上插入了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

乜一 2024-12-29 08:50:31

您可以使用 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 ...

You can use adb devices to get a list of connected devices and then run adb -s DEVICE_SERIAL_NUM install... for every device listed.

Something like (bash):

adb devices | tail -n +3 | cut -sf 1 -d " " | xargs -iX adb -s X install ...

Comments suggest this might work better for newer versions:

adb devices | tail -n +2 | cut -sf 1 | xargs -iX adb -s X install ...

For Mac OSX(not tested on Linux):

adb devices | tail -n +2 | cut -sf 1 | xargs -I {} adb -s {} install ...
染墨丶若流云 2024-12-29 08:50:31

其他答案非常有用,但并没有完全满足我的需要。我想我应该发布我的解决方案(一个 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"

感谢您提供的所有其他答案让我走到这一步。

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

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"

Thank you for all the other answers that got me to this point.

稀香 2024-12-29 08:50:31

这是根据 kichik 的回复定制的实用单行命令(谢谢!):

adb 设备 |尾-n +2 |切-sf 1 | xargs -iX adb -s X install -r *.apk

但如果你碰巧使用 Maven,那就更简单了:

mvn android:部署

Here's a functional one line command tailored from kichik's response (thanks!):

adb devices | tail -n +2 | cut -sf 1 | xargs -iX adb -s X install -r *.apk

But if you happen to be using Maven it's even simpler:

mvn android:deploy

如日中天 2024-12-29 08:50:31

另一个简短的选择...我偶然发现此页面,发现 -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

Another short option... I stumbled on this page to learn that the -s $SERIAL has to come before the actual adb command! Thanks stackoverflow!

for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s $SERIAL install -r /path/to/product.apk`;
done
月亮邮递员 2024-12-29 08:50:31

Dave Owens 在所有设备上运行任何命令的通用解决方案:

for SERIAL in $(adb devices | grep -v List | cut -f 1);
do echo adb -s $SERIAL $@;
done

将其放入“adb_all”等脚本中,并使用与单个设备的 adb 相同的方式。

我发现的另一件好事是为每个命令分叉后台进程,并等待它们完成:

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

Generalized solution from Dave Owens to run any command on all devices:

for SERIAL in $(adb devices | grep -v List | cut -f 1);
do echo adb -s $SERIAL $@;
done

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:

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

Then you can easily create a script to install app and start the activity

./adb_all_fork install myApp.apk
./adb_all_fork shell am start -a android.intent.action.MAIN -n my.package.app/.MainActivity
别理我 2024-12-29 08:50:31

我喜欢 workingMatt 的脚本,但认为它可以改进一点,这是我的修改版本:

#!/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

我的版本做了同样的事情,除了:

  • 的项目的根目录中找到apk
  • 它从它同时安装到每个设备
  • ,它排除了apk的“未对齐”版本(这些只是由对齐版本安装的,无论如何
  • 它显示了可读的手机的名称而不是设备 ID

有几种方法仍然可以改进,但我对此非常满意。

I liked workingMatt's script but thought it could be improved a bit, here's my modified version:

#!/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

My version does the same thing except:

  • it finds the apks from the root of the project
  • it installs to every device simultaneously
  • it excludes the "unaligned" versions of the apks (these were just being installed over by the aligned versions anyway
  • it shows the readable names for the phones instead if their device ids

There's a few ways it could still be improved but I'm quite happy with it.

茶花眉 2024-12-29 08:50:31

以下命令应该有效:

$ 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 devices 返回设备列表。使用 tail -n +2 从第二行开始,使用 head -n -1 删除末尾的最后一个空行。使用默认制表符分隔符进行管道传输可以得到第一列,即序列号。

xargs 用于为每个序列运行 adb 命令。如果不重新安装,请删除 -r 选项。

The following command should work:

$ 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 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.

枫以 2024-12-29 08:50:31

使用这个脚本,你可以做到:

adb+ install <path to apk>

干净、简单。

With this script you can just do:

adb+ install <path to apk>

Clean, simple.

风透绣罗衣 2024-12-29 08:50:31

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) 中,重新启动 shell,您可以使用以下命令调用安装:

adba install yourApp.apk

PowerShell solution

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)
    }
}

Put this in your profile file (notepad $PROFILE), restart your shell and you can invoke installations with :

adba install yourApp.apk
东风软 2024-12-29 08:50:31

如果您不想使用未启用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

If you don't want use the devices that have not enabled adb; use this

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
顾铮苏瑾 2024-12-29 08:50:31

使用此命令行实用程序:adb-foreach

Use this command-line utility: adb-foreach

南汐寒笙箫 2024-12-29 08:50:31

这个命令完美运行
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

丘比特射中我 2024-12-29 08:50:31

很简单,您可以创建一个 installapk.bat 文件,该文件可以将多个 apk 完成到多个连接设备的工作,使用 notepad++ 打开 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

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

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
过期以后 2024-12-29 08:50:31

这是用于在所有连接的设备上安装和运行 apk 的 bash

使用

nick@nickolay:/home/workspace/MyProject$ > bash 路径/to/installAndRunApk.sh

installAndRunApk.sh

#!/usr/bin/env bash
#--------find apk---------
apkFile=$(find -name '*.apk' -print | grep -oP '(?<=.).*(.apk)')

#--------find apkFilePath---------
if test -z "apkFile"
then
echo "apkFile: is NULL"
exit 0;
fi

echo "apkFile: ${apkFile}"
apkFilePath=$(pwd)${apkFile}
echo "apk file path: ${apkFilePath}"

#--------install---------
if test -z "$apkFilePath"
then
echo "apkFilePath: is NULL"
exit 0;
fi

echo "adb install -t -r ${apkFilePath}"
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s ${SERIAL} install -t -r ${apkFilePath}`;
done

#--------get applicationId---------
echo "aapt dump badging ${apkFilePath} | grep -oP '(?<=package: name=).*(?=versionCode)'"
applicationId=$(aapt dump badging ${apkFilePath} | grep -oP '(?<=package: name=).*(?=versionCode)')
echo "applicationId: is ${applicationId}"

#--------launch---------
if test -z "$applicationId"
then
echo "applicationId: is NULL"
exit 0;
fi

echo "____________________START_APPLICATION_ID________________________"
echo "applicationId: ${applicationId}"
echo "____________________END_APPLICATION_ID__________________________"
echo "____________________START_LAUNCHER______________________________"
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s ${SERIAL} shell monkey -p ${applicationId} -c android.intent.category.LAUNCHER 1`;
done
echo "____________________END_LAUNCHER________________________________"

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

#!/usr/bin/env bash
#--------find apk---------
apkFile=$(find -name '*.apk' -print | grep -oP '(?<=.).*(.apk)')

#--------find apkFilePath---------
if test -z "apkFile"
then
echo "apkFile: is NULL"
exit 0;
fi

echo "apkFile: ${apkFile}"
apkFilePath=$(pwd)${apkFile}
echo "apk file path: ${apkFilePath}"

#--------install---------
if test -z "$apkFilePath"
then
echo "apkFilePath: is NULL"
exit 0;
fi

echo "adb install -t -r ${apkFilePath}"
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s ${SERIAL} install -t -r ${apkFilePath}`;
done

#--------get applicationId---------
echo "aapt dump badging ${apkFilePath} | grep -oP '(?<=package: name=).*(?=versionCode)'"
applicationId=$(aapt dump badging ${apkFilePath} | grep -oP '(?<=package: name=).*(?=versionCode)')
echo "applicationId: is ${applicationId}"

#--------launch---------
if test -z "$applicationId"
then
echo "applicationId: is NULL"
exit 0;
fi

echo "____________________START_APPLICATION_ID________________________"
echo "applicationId: ${applicationId}"
echo "____________________END_APPLICATION_ID__________________________"
echo "____________________START_LAUNCHER______________________________"
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s ${SERIAL} shell monkey -p ${applicationId} -c android.intent.category.LAUNCHER 1`;
done
echo "____________________END_LAUNCHER________________________________"
鸠书 2024-12-29 08:50:31

我添加了@WorkingMatt 的答案

我更新了他的答案,另外执行以下操作

  1. 尝试连接到网络上的所有设备开放端口 5555 的本地网络。警告:这可能存在安全风险。小心连接到任意端口,除非您知道它是安全的。我没有接受过网络安全方面的培训,所以请对我的建议持保留态度。
  2. 如果已安装软件包,则卸载以前版本的软件包(在我的情况下,我卸载以删除以前的应用程序数据)
#!/bin/bash
echo "Installatron2"

# Connect to all devices on the local network (in our case 192.168.0.0)
# This section requires nmap (You may need sudo apt install nmap)
echo "Scanning the network for connected debuggable devices"
ADDRESSES=$(nmap --open -p 5555 192.168.0/24 -oG - | grep "/open" | awk '{ print $2 }')
for ADDRESS in $ADDRESSES;
do
  adb connect $ADDRESS
done

# Print devices connected to
echo "Connected to the following devices"
echo "$(adb devices)"

# Iterate through all apks in current directory
for SERIAL in $(adb devices | tail -n +2 | cut -sf 1);
do
  for APKLIST in $(ls *.apk);
  do
  #Get the package name from the apk file (Needs sudo apt install aapt)
  package=$(aapt dump badging "$APKLIST" | awk '/package/{gsub("name=|'"'"'","");  print $2}')

  # Optionally uninstalls the pre-existing version of this package (In case you do not want to retain data)
  echo "Uninstalling $package on $SERIAL"
  adb uninstall $package

  # Now install with replacement to the same device
  echo "Installatroning $APKLIST on $SERIAL"
  adb -s $SERIAL install -r $APKLIST
  done
done

echo "Installatron2 has left the building"

I added to the answer from @WorkingMatt

I updated his answer to additionally do the following things

  1. Attempt to connect to all devices on the local network with open port 5555. Warning: this may be a security risk. Beware connecting to arbitrary ports unless you know that it is safe. I am not trained in cybersecurity, so take my advice here with a grain of salt.
  2. Uninstall the previous version of the package if there is one installed (In my case I am uninstalling to remove previous app data)
#!/bin/bash
echo "Installatron2"

# Connect to all devices on the local network (in our case 192.168.0.0)
# This section requires nmap (You may need sudo apt install nmap)
echo "Scanning the network for connected debuggable devices"
ADDRESSES=$(nmap --open -p 5555 192.168.0/24 -oG - | grep "/open" | awk '{ print $2 }')
for ADDRESS in $ADDRESSES;
do
  adb connect $ADDRESS
done

# Print devices connected to
echo "Connected to the following devices"
echo "$(adb devices)"

# Iterate through all apks in current directory
for SERIAL in $(adb devices | tail -n +2 | cut -sf 1);
do
  for APKLIST in $(ls *.apk);
  do
  #Get the package name from the apk file (Needs sudo apt install aapt)
  package=$(aapt dump badging "$APKLIST" | awk '/package/{gsub("name=|'"'"'","");  print $2}')

  # Optionally uninstalls the pre-existing version of this package (In case you do not want to retain data)
  echo "Uninstalling $package on $SERIAL"
  adb uninstall $package

  # Now install with replacement to the same device
  echo "Installatroning $APKLIST on $SERIAL"
  adb -s $SERIAL install -r $APKLIST
  done
done

echo "Installatron2 has left the building"
旧情别恋 2024-12-29 08:50:31

使用 Android Debug Bridge 版本 1.0.29,尝试这个 bash 脚本

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

不确定它是否适用于早期版本。

With Android Debug Bridge version 1.0.29, try this 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

Not sure if it works with earlier versions.

夏了南城 2024-12-29 08:50:31

关键是在单独的进程 (&) 中启动 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: STDOUT 和 STDERR 被抑制。您不会看到任何“adb install”操作结果。我想,如果您确实需要

注意2:,这可能会得到改进,您还可以通过提供参数而不是硬编码的路径和活动名称来改进脚本。

这样您就可以:

  1. 不必在每台设备上手动执行安装
  2. 不必等待一个安装完成才能执行另一个安装(adb 任务并行启动)

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:

#!/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"

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:

  1. Don't have to manually perform install on each device
  2. Don't have to wait for one install to finish in order to execute another one (adb tasks are launched in parallel)
酒浓于脸红 2024-12-29 08:50:31

源自这里:将上一篇文章设为 Mass APK不使用 ADB Install-Multi 语法的安装程序


@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     ##
::: ##########################################################################

Originated from here: 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     ##
::: ##########################################################################

述情 2024-12-29 08:50:31

由于我无法评论 @Tom 的答案,这对我在 OSX 10.13 上有效

adb devices | tail -n +2 | cut -sf 1 | xargs -IX adb -s X install -r path/to/apk.apk

(将小 i 更改为大 I)

Since I can't comment on the answer by @Tom, this worked for me on OSX 10.13

adb devices | tail -n +2 | cut -sf 1 | xargs -IX adb -s X install -r path/to/apk.apk

(Change the little i to a big I)

晨与橙与城 2024-12-29 08:50:31

我想记录安装时发生的情况,也需要它稍微易于理解。最终结果是:

echo "Installing app on all connected devices."

adb devices | tail -n +2 | cut -sf 1 | xargs -I % sh -c '{ \
    echo "Installing on %"; \
    adb -s % \
        install myApp.apk; \    
; }'

在 Linux 上进行了测试苹果

I was wanting to log what was happening whilst installing, also needed it to be slightly comprehendable. Ended up with:

echo "Installing app on all connected devices."

adb devices | tail -n +2 | cut -sf 1 | xargs -I % sh -c '{ \
    echo "Installing on %"; \
    adb -s % \
        install myApp.apk; \    
; }'

Tested on Linux & Mac

你是年少的欢喜 2024-12-29 08:50:31

-获取.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

-Get all the apk stored in .apk folder

-Install and replace app on devices

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文