'cordova build android' fails due to dependencies

I’m a first-time user of cordova and I have no prior experience with Android Studio, so please be kind.

Background: Following the android dependencies of cordova documented at cordova.apache.org, I installed Gradle 8.7, Kotlin 1.9.22, and java version “1.8.0_101”. While it requires Gradle 8.7, cordova.apache.org also lists the required Gradle Plugin version as 8.3. In Android Studio | Settings… | Plugins I see that a plugin for Gradle has been installed, but I don’t see any way to control the version of the plugin that is installed.

Ok, so when building a new project in cordova I get the following build error, but I don’t see why it is picking up Gradle 8.3:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'MyProject'.
> Could not resolve all artifacts for configuration ':classpath'.
   > **Could not resolve com.android.tools.build:gradle:8.3.0**.
     Required by:
         project :
      > No matching variant of com.android.tools.build:**gradle:8.3.0** was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' **with value '8.7'** but:
          - **Variant 'apiElements' declares a library**, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, **compatible with Java 11** and the consumer needed a component for use during runtime, **compatible with Java 8**
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')

It is not using Gardle 8.3, it is using Gradle 8.7.
It is using Android Gradle Plugin 8.3.0.
Unfortunately Google choose to use the unlucky naming gradle for their Android Gradle Plugin artifact so occasionally people mix up the Gradle version and the Android Gradle Plugin version.

What the error is trying to tell you is, that you run Gradle using Java 8, but the Android Gradle Plugin 8.3.0 requires that you run Gradle with at least Gradle 11.

That’s what I was guessing might be the cause, but (a) cordova.apache.org specifically requires this combination (Gradle 8.7 with Android Gradle Plugin: 8.3.0), and (b) I didn’t see any way to control which version of the Android Gradle Plugin is used. Is there a way? Also, since Gradle 8.7 was compiled with Java 8 and the Android Gradle Plugin 8.3 was compiled with Java 11, then is there some way to work around this error?

Why don’t you want to use Java 11 to run Gradle?

Thank you. I’m blaming this on my failing eyesight. The solution was to uninstall the old version of the Java SDK and reinstall Java 17. Boom. Thank you!!

1 Like

Setting JAVA_HOME to a newer JDK, or configuring the IDE to use a newer JDK for Gradle would actually have been enough. :smiley: