@MotohawkSF's answer did not worked for me in Android Studio terminal. What worked though was using the name of the device after running adb devices
> adb devices
List of devices attached
192.168.22.122:5555 device
emulator-5554 device
then
set ANDROID_SERIAL=192.168.22.122:5555
gradlew someTask