I am getting this error while I am building APK.
Cause 1: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while
If you've tried all the solutions above and still doesn't resolve your issue.
This might not seemed related, but here's my take on it.
Try removing this from your Gradle dependency, I've spend 2 hours of my time because of this roadblock.
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"