The problem was I set proxy details of my University proxy server for
internet access in Android Studio. When this problem appeared I tried
build the project with proxy on internet connection with proxy but it
did not work.
Then I removed the proxy from Android Studio preferences and
connected to non-proxy internet connection but the problem did not
disappear.
Then I Googled a lot and came here but could not find the root cause.
I updated AS from 3.1.3 to 3.2 but the problem still persisted.
Finally, I started looking for hidden proxy server details in AS and
found them in gradle.properties file located Gradle ->
Resource Bundle 'gradle' -> gradle.properties.
Deleted the proxy server details in this file and ran the build with
successful completion after performing some packages update on the suggestions Android Studio.