others-how to solve `java.lang.RuntimeException: Minimum supported Gradle version is x.x.x. Current version is y.y.y` when trying to build android app?

1. Purpose

Sometime when we trying to build android app as follows:

Starting Gradle Daemon...
Gradle Daemon started in 827 ms
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.6.4/gradle-3.6.4.pom
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.6.4/builder-3.6.4.pom
Download https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/crash/26.6.4/
....
Download https://dl.google.com/dl/android/maven2/androidx/databinding/databinding-compiler-common/3.6.4/databinding-compiler-common-3.6.4.jar

FAILURE: Build failed with an exception.

The real error message is as follows:


* Where:
Build file '/Users/bswen/myproject/testapp/app/build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.version-check']
   > Minimum supported Gradle version is 5.6.4. Current version is 4.4. If using the gradle wrapper, try editing the distributionUrl in /Users/bswen/myproject/testapp/gradle/wrapper/gradle-wrapper.properties to gradle-5.6.4-all.zip

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:92)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:199)
    at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:204)
    ... 94 more
Caused by: java.lang.RuntimeException: Minimum supported Gradle version is 5.6.4. Current version is 4.4. If using the gradle wrapper, try editing the distributionUrl in /Users/bswen/myproject/testapp/gradle/wrapper/gradle-wrapper.properties to gradle-5.6.4-all.zip
    at com.android.build.gradle.internal.plugins.VersionCheckPlugin.apply(VersionCheckPlugin.kt:58)
    at com.android.build.gradle.internal.plugins.VersionCheckPlugin.apply(VersionCheckPlugin.kt:34)
    at org.gradle.api.internal.plugins.ImperativeOnlyPluginTarget.applyImperative(ImperativeOnlyPluginTarget.java:42)
    at org.gradle.api.internal.plugins.RuleBasedPluginTarget.applyImperative(RuleBasedPluginTarget.java:50)
    at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:165)
    at org.gradle.api.internal.plugins.DefaultPluginManager.access$200(DefaultPluginManager.java:47)
    at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:252)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
    ... 123 more


* Get more help at https://help.gradle.org

CONFIGURE FAILED in 1m 12s

The core error message is:

> Failed to apply plugin [id 'com.android.internal.version-check']
   > Minimum supported Gradle version is 5.6.4. Current version is 4.4. If using the gradle wrapper, try editing the distributionUrl in /Users/bswen/myproject/testapp/gradle/wrapper/gradle-wrapper.properties to gradle-5.6.4-all.zip



2. Environment

This project build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.6.4"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

This project local.properties

sdk.dir=/Users/bswen/Library/Android/sdk

project settings.gradle

include ':app'

project ./gradle/wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

3. Solution

We are using the inproper version of gradle , so we should try to change ./gradle/wrapper/gradle-wrapper.properties, modify the distributionUrl to new gradle version:

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

The recommended way to execute any Gradle build is with the help of the Gradle Wrapper (in short just “Wrapper”). The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary. As a result, developers can get up and running with a Gradle project quickly without having to follow manual installation processes saving your company time and money.

What is distributionUrl in gradle-wrapper.properties?

Projects will typically want to keep up with the times and upgrade their Gradle version to benefit from new features and improvements. One way to upgrade the Gradle version is manually change the distributionUrl property in the Wrapper’s gradle-wrapper.properties file.



4. Summary

In this post, I demonstrated how to java.lang.RuntimeException: Minimum supported Gradle version is x.x.x. Current version is y.y.y when trying to build android app, the key point is to upgrade your gradle version in your gradle-wrapper.properties. That’s it, thanks for your reading.