After upgrading to Android Studio 3.1.2 I am getting the following error:
Configuration on demand is not supported by the current version of the Andro
Update the gradle version
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
Build > Rebuild Project
Good Luck
Source