Created
December 3, 2018 16:26
-
-
Save OleksandrKucherenko/664f107383d2b44c09a1f4bc81b79b12 to your computer and use it in GitHub Desktop.
Script force all 'installDebug' task wait 10 seconds for device attaching.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static isAnyDeviceOnline() { | |
def start = System.currentTimeMillis() | |
def firstTime = true | |
while (System.currentTimeMillis() - start < 10000) { | |
def out = new StringBuilder() | |
def process = 'adb devices -l'.execute() | |
process.consumeProcessOutput(out, null) | |
process.waitForOrKill(1000) | |
if (out.toString().contains("device ")) return | |
if (firstTime) { | |
firstTime = false | |
println 'INFO: Waiting 10s for any ADB device' | |
println "${out.toString()}" | |
} | |
Thread.sleep(1000) | |
} | |
throw new GradleException('Timeout. Cannot detect any connected online device') | |
} | |
gradle.projectsEvaluated { | |
// Grab all build types and product flavors | |
def buildTypes = android.buildTypes.collect { type -> type.name } | |
def productFlavors = android.productFlavors.collect { flavor -> flavor.name } | |
// When no product flavors defined, use empty | |
if (!productFlavors) productFlavors.add("") | |
productFlavors.each { flavor -> | |
buildTypes.each { buildt -> | |
def task = project.tasks.findByName("install${flavor.capitalize()}${buildt.capitalize()}") | |
if (null != task) task.doFirst { isAnyDeviceOnline() } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: just copy and paste code into end of the
app/build.gradle
file