How can I adb install an apk to multiple connected devices?

后端 未结 20 1820
余生分开走
余生分开走 2020-11-30 19:03

I have 7 devices plugged into my development machine.

Normally I do adb install and can install to just a single device.

Now

相关标签:
20条回答
  • 2020-11-30 19:33

    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 ...
    
    0 讨论(0)
  • 2020-11-30 19:34

    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
    
    0 讨论(0)
提交回复
热议问题