1

I appear to be getting this Gradle error after updating a project:

Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org.gradle.configureondemand=false in your gradle.properties file or use a Gradle version less than 4.6.

When the tab is opened up for further examination it appears as below:

org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'com.android.application']
Caused by: org.gradle.api.tasks.StopExecutionException: Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org.gradle.configureondemand=false in your gradle.properties file or use a Gradle version less than 4.6.

I have tried the 2 suggestions that it has separately and together to no avail. Please see my Gradle files below.

Gradle Project File

buildscript {
ext.kotlin_version = '1.2.50'
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "io.realm:realm-gradle-plugin:5.0.0"
    classpath 'com.google.gms:google-services:4.0.0'




    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
allprojects {
repositories {
    google()
    jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Gradle Module File

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'realm-android'

apply plugin: 'kotlin-kapt'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.blah.blah"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        postprocessing {
            removeUnusedCode false
            removeUnusedResources false
            obfuscate false
            optimizeCode false
            proguardFile 'proguard-rules.pro'
        }
    }
}}
dependencies {
implementation 'com.stripe:stripe-android:6.1.2'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'junit:junit:4.12'
implementation "cz.msebera.android:httpclient:4.4.1.2"

implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-core-utils:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation  'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation files('libs/stripe-java-5.23.1.jar')
implementation  'com.android.volley:volley:1.0.0'
implementation  'com.google.code.gson:gson:2.8.2'}

apply plugin: 'com.google.gms.google-services'

Gradle Properties Files

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
#org.gradle.parallel=true

I'm hoping someone can enlighten me. I will upload more file data if you need it.

stkent
  • 19,772
  • 14
  • 85
  • 111
DNA
  • 117
  • 1
  • 3
  • 10

2 Answers2

5

As per the error. You need to

Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org.gradle.configureondemand=false in your gradle.properties file or use a Gradle version less than 4.6.

so do

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
org.gradle.configureondemand=false

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
#org.gradle.parallel=true

Note: There's also an option in IDE "Configure on demand"(search in search tool, you will find it under "compiler" option) uncheck that option and adding "org.gradle.configureondemand=false" in global gradle properties file which is usually in C drive(windows) or in your OS partition(MAC or linux) and don't forget to enable hidden files (windows-> view options and Mac command+shift+.)

Find more at

configuration on demand in Gradle

what exactly is “configuration on demand” in Gradle?


or you can also downgrade your gradle version.

Goto Project->Gradle->wrapper and open gradle-wrapper.properties file

and change the value of distributionUrl as

distributionUrl = https\://services.gradle.org/distributions/gradle-4.4-all.zip

Supported gradle versions in android

Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
  • you might need to change `classpath 'com.android.tools.build:gradle:3.1.3'` to `classpath 'com.android.tools.build:gradle:3.1.2'` – Pavneet_Singh Jun 20 '18 at 01:00
  • I tried all three of the above methods and the only one that worked is downgrading Gradle. Thank you for your help. Note: Using "org.gradle.configureondemand=false" did not work for some reason. It just gave the same error. – DNA Jun 20 '18 at 02:19
  • actually there are couple of other place which has this option enabled , in studio and in global gradle properties files as well – Pavneet_Singh Jun 21 '18 at 00:49
1

Click File on Android Studio Menu List, and choose Invalidate Caches, and then it will show you a dialog, Click the Invalidate and Restart. It works for me. Additionally, I have set org.gradle.configureondemand=false in your gradle.properties as Pavneet_Singh said above before invalidating caches.

Chinese Cat
  • 5,359
  • 2
  • 16
  • 17