#CI #gradle #android
Recently I have integrated baseline profiles and benchmarks into the project I am working on. The issue I hit was that running `gradle build` failed on CI.
Why? Because `build` includes assembling, testing and checking the build. And testing `benchmark` and `baseline-profile` modules means running instrumented tests. Since the CI we are using has no devices connected it naturally fails.
## Solution
Since we are not going to run instrumented tests on CI anytime soon (and even when we do, we are not going to run them every time) I decided to disable them:
```groovy
if (System.getenv('BUILD_ID') != null) {
gradle.taskGraph.whenReady { graph ->
graph.allTasks.findAll { it.name ==~ /connected.*/ }*.enabled = false
graph.allTasks.findAll { it.name ==~ /^collect.*BaselineProfile$/ }*.enabled = false
}
}
```
What this does is if gradle script is running onCI (you might have to adjust env variable to work with your CI) it waits while task graph is created and disables connected and baseline profiles tasks.
This is kinda a nuclear approach and we will have to revisit this implementation when we start using Firebase Test Lab or something similar but it does solve the problem meanwhile.
Hope this saves someone a bit of time.