I am new in the web,android development world.
I am getting started on a project in Capacitor js, followed the instructions in the documentation when I run cap run android it crushed
Running Gradle build – failed!
[error] Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not
be reused, use –status for details
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:8.2.1.
Required by:
project :
> No matching variant of com.android.tools.build:gradle:8.2.1 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.2.1' but:
- Variant 'apiElements' capability com.android.tools.build:gradle:8.2.1
declares a library, packaged as a jar, and its dependencies declared
It work on Android Studio.
windows 11
in my environment variables i have:
ANDROID HOME : C:UsersuserAppDataLocalAndroidSdk
path: C:Program FilesJavajdk-20
C:Program FilesJavajdk-20bin
C:Program FilesJavajre-1.8
JAVA HOME C:Program FilesJavajre-1.8
I expect to have a solutions
2
Answers
You are currently using Java 8 but need to use Java 17 for Capacitor 6.
If your application runs in Android Studio, but not with the
npx cap run
command, the issue is generally about yourJAVA_HOME
environment variable. You haveJAVA HOME C:Program FilesJavajre-1.8
, an older version of JAVA incompatible with the latest Capacitor.The reason is, Android Studio installs its own JDK/JRE and uses it. However, your capacitor CLI might not recognise this version as it’s not defined in the path. You can check which JAVA your Android Studio is using by checking the settings, see:finding-android-studio-java-path.
You can then, change your
JAVA_HOME
environment variable to use the same JAVA path as the Android Studio. see the tutorial to achieve this.