如果连接了多个模拟器/设备,是否可以安装 APK 文件

我知道如何通过命令提示符将 apk 文件安装到模拟器中。 但我想知道是否有可能安装相同的 apk 文件到多个模拟器给予任何特定的名称? 事实上,我必须测试一个 apk 文件在许多设备。为此,我已经启动了许多设备。我知道怎么安装。如果所有设备都是打开的,那么它将不会得到安装。那么,是否有其他方法可以通过给出特定设备模拟器 ID 或任何名称来安装 apk 文件? ? 请帮助我,如果它有任何想法. 。 谢谢。

82914 次浏览

yes you can install your apk file in multiple emulator for that you have to give the name in command prompt here is the link for guidance

http://developer.android.com/guide/developing/tools/emulator.html

Yes, you can install an apk on a particular device.

In command, type:

adb devices
// list of devices and its unique ID...

Then type:

adb -s "<deviceIDfromlist>" install "<path-to-apk>"

Step 1: Get the device Ids of all connected device

adb devices

Step 2: Install to a particular device you want to install

adb -s deviceId install path+apk

Example:

Step 1:

C:\Android\android-sdks\platform-tools>adb devices

List of devices attached emulator-5554 device 014FD87107021017
device

Step 2:

C:\Android\android-sdks\platform-tools>adb -s 014FD87107021017 install C:\Users\
user\Documents\appname.apk

Use the following scripts to install apk on multiple devices/emulators.

    for SERIAL in $(adb devices | grep -v List | cut -f 1);
do adb -s $SERIAL install -r /path/to/product.apk;
done

Remove -r if you are not reinstalling the apk. Also you can replace "install -r /path/to/product.apk" to other adb commands like working on one single device.

It works for me on real devices but I believe it should also works for emulators.

It is possible to issue install command simultaneously on all connected devices.

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)

You can install on multiple devices at a time using USB debugging.

In Eclipse Run--> Run Configurations --> choose your project (on left) -->Target --> Launch on All compatible devices.

The selected project will be installed on all the connected devices