I was having this error when deploying a signed APK of my App, running and debugging were both working fine.
After two hours fighting this issue, this was the solution
generateStubs = true
I placed the “kapt” block before the “dependencies” one and after “android”. Now I can deploy signed APKs