'How to solve the gradle caching ANDROID_SERIAL problem?

In order to run android test on different devices, I'm using the following command

ANDROID_SERIAL=ZY22F757TO  ./gradlew -Pandroid.testInstrumentationRunnerArguments.class=com.example.id.Debug#debug connectedAndroidTest

But there's an error like:

Device FQQ336X28100 not found

Because I just tested

ANDROID_SERIAL=FQQ336X28100  ./gradlew -Pandroid.testInstrumentationRunnerArguments.class=com.example.id.Debug#debug connectedAndroidTest

And it seems that gradle cached the ANDROID_SERIAL, here's my solution:

pkill -f '.*gradle.*';ANDROID_SERIAL=ZY22F757TO  ./gradlew -Pandroid.testInstrumentationRunnerArguments.class=com.example.id.Debug#debug connectedAndroidTest

It did work, but in this case, I can't run multiple devices at the same time.

Just wondering if anything I had missed?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source