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

后端 未结 20 2017
余生分开走
余生分开走 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:24

    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.

提交回复
热议问题