FAILURE: Build failed with an exception.
* Where:
Build file '/bitrise/src/app/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
Gradle detects locally installed JVMs Gradle chooses a JRE/JDK matching the requirements of the build (in this case a JVM supporting Java 14) If no matching JVM is found, it will automatically download a matching JDK from AdoptOpenJDK
Does Android Gradle Plugin support the new gradle toolchains? https://docs.gradle.org/current/userguide/toolchains.html
Notable libraries / plugins / versions
App module gradle config below (some details removed)
android {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
kotlinOptions {
jvmTarget = Versions.jdkNumber
useIR = true
}
buildToolsVersion Config.buildToolsVersion
compileSdkVersion Config.compileSdk
buildFeatures {
compose true
dataBinding true
}
composeOptions {
kotlinCompilerVersion Versions.kotlin_version
kotlinCompilerExtensionVersion Versions.compose
}
androidExtensions {
experimental = true
}
}
Right click on the deploy or any other task and select "Open Gradle Run Configuration..." Then navigate to "Java Home" and paste your desired java path.
Gradle can only run on Java version 8 or higher. Gradle still supports compiling, testing, generating Javadoc and executing applications for Java 6 and Java 7.
Gradle 6.7 introduces “Java toolchain support”. In a nutshell, it allows you to run Gradle with whatever version of Java you have installed, while Gradle builds the project with the version of Java declared in a single place.
This chapter explains how to build a java project using Gradle build file. First of all, we have to add java plugin to the build script, because, it provides the tasks to compile Java source code, to run the unit tests, to create a Javadoc and to create a JAR file. Use the following line in build.gradle file.
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8 I'm trying to use a physical Android device to test/debug my React Native project. I connected the device to my Windows 11 machine via USB and turned on Developer mode on the device but when I tried to run my project, I got an error stating the following:
Additionally, you may want to build a project using a Java version that is not supported for running Gradle. A Java Toolchain (from now on referred to simply as toolchain) is a set of tools, usually taken from a local JRE/JDK installation that are used to configure different aspects of a build.
If you ran gradle build to build the project now, the build would fail because you have not declared Joda Time as a compile dependency in the build. For starters, you need to add a source for 3rd party libraries.
You might check this out. I had a similar problem and it fixed it for me. This is Gradle's own "snippet" of code for the problem you're facing.
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
plugins {
id "org.jetbrains.kotlin.jvm" version "1.4.20"
}
repositories {
jcenter()
}
// tag::compiler-kotlin[]
def compiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(11)
}
tasks.withType(KotlinJvmCompile).configureEach {
kotlinOptions.jdkHome = compiler.get().metadata.installationPath.asFile.absolutePath
}
// end::compiler-kotlin[]
This was found at https://github.com/gradle/gradle/blob/master/subprojects/docs/src/snippets/java/toolchain-kotlin/groovy/build.gradle
I incorporated it in my project at https://github.com/7ep/r3z/blob/51cc69bb6396c34f0507b67763487c9bc171a03e/build.gradle#L36
Good luck!
Byron
Just solved this by adding jitpack.yml
file in project root folder with content:
jdk:
- openjdk11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With