Skip to content

Instantly share code, notes, and snippets.

@mikepenz
Last active July 27, 2017 12:20
Show Gist options
  • Save mikepenz/9e828b4f9728a7efd4eb3cddcf3daa22 to your computer and use it in GitHub Desktop.
Save mikepenz/9e828b4f9728a7efd4eb3cddcf3daa22 to your computer and use it in GitHub Desktop.
android-gradle-logger
gradle.taskGraph.afterTask { task, state ->
if (task. state.failure) {
println "$task.name FAILED PRINTING LOGS"
getDevicesAndReadLogs(500)
}
}
ext.getDevicesAndReadLogs = { count = 2500 ->
try {
def outstream = new ByteArrayOutputStream()
exec {
executable "sh"
workingDir '.'
args "-c", "adb devices -l"
standardOutput = outstream
}
outstream.toString().split("\n").each {
if (!it.contains("List of devices")) {
def parts = it.split(" ");
readTestLogs(parts[0], count);
}
}
} catch (Exception ex) {
println("Failed to do getDevicesAndReadLogs because of: " + ex)
}
}
ext.readTestLogs = { device, count ->
try {
def outstream = new ByteArrayOutputStream()
exec {
executable "sh"
workingDir '.'
args "-c", "adb -s " + device + " shell logcat -n " + count + " -d '*:E'"
standardOutput = outstream
}
outstream.toString().split("\n").each {
println(it);
}
} catch (Exception ex) {
println("Failed to read log for " + device + " because of: " + ex)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment