Skip to content

Commit

Permalink
fix: jvm 11 error message from ReactPlugin.kt and react.gradle (#33048)
Browse files Browse the repository at this point in the history
Summary:
you can see discussion here: reactwg/react-native-releases#13 (comment)
we were getting this error message when we build Gradle with other than 11 JVM
```
> Task :react-native-gradle-plugin:compileJava FAILED
2 actionable tasks: 2 executed

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileJava'.
> invalid source release: 11
```
this solution is suggested by mikehardy

after this PR, now the error is like this
```
**************************************************************************************************************

ERROR: requires JDK11 or higher.
Incompatible major version detected: '8'

**************************************************************************************************************
```

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - jvm 11 error message

Pull Request resolved: #33048

Test Plan: install other than 11 java version and just run `./scripts/test-manual-e2e.sh` this command at the root of RN repo than this error will appair `invalid source release: 11`

Reviewed By: ShikaSD

Differential Revision: D34110990

Pulled By: cortinico

fbshipit-source-id: c142a363c7cec0db65d5ab9da858fd25866c7c49
  • Loading branch information
numandev1 authored and facebook-github-bot committed Feb 9, 2022
1 parent eafa5bc commit 4e947ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,37 @@ import com.facebook.react.tasks.BuildCodegenCLITask
import com.facebook.react.tasks.GenerateCodegenArtifactsTask
import com.facebook.react.tasks.GenerateCodegenSchemaTask
import java.io.File
import kotlin.system.exitProcess
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.internal.jvm.Jvm

class ReactPlugin : Plugin<Project> {
override fun apply(project: Project) {
checkJvmVersion()
val extension = project.extensions.create("react", ReactExtension::class.java, project)
applyAppPlugin(project, extension)
applyCodegenPlugin(project, extension)
}

private fun checkJvmVersion() {
val jvmVersion = Jvm.current()?.javaVersion?.majorVersion
if ((jvmVersion?.toIntOrNull() ?: 0) <= 8) {
println("\n\n\n")
println(
"**************************************************************************************************************")
println("\n\n")
println("ERROR: requires JDK11 or higher.")
println("Incompatible major version detected: '" + jvmVersion + "'")
println("\n\n")
println(
"**************************************************************************************************************")
println("\n\n\n")
exitProcess(1)
}
}

private fun applyAppPlugin(project: Project, config: ReactExtension) {
project.afterEvaluate {
if (config.applyAppPlugin.getOrElse(false)) {
Expand Down
14 changes: 14 additions & 0 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.jvm.Jvm

def config = project.hasProperty("react") ? project.react : [:];

Expand Down Expand Up @@ -129,6 +130,19 @@ android {
}
}

def jvmVersion = Jvm.current().javaVersion.majorVersion
if (jvmVersion.toInteger() <= 8) {
println "\n\n\n"
println "**************************************************************************************************************"
println "\n\n"
println "ERROR: requires JDK11 or higher."
println "Incompatible major version detected: '" + jvmVersion + "'"
println "\n\n"
println "**************************************************************************************************************"
println "\n\n\n"
System.exit(1)
}

afterEvaluate {
def isAndroidLibrary = plugins.hasPlugin("com.android.library")
def variants = isAndroidLibrary ? android.libraryVariants : android.applicationVariants
Expand Down

0 comments on commit 4e947ec

Please sign in to comment.