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

后端 未结 20 1985
余生分开走
余生分开走 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条回答
  •  -上瘾入骨i
    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
    

提交回复
热议问题