Skip to content

Commit 4e947ec

Browse files
numandev1facebook-github-bot
authored andcommitted
fix: jvm 11 error message from ReactPlugin.kt and react.gradle (#33048)
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
1 parent eafa5bc commit 4e947ec

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt

+20
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,37 @@ import com.facebook.react.tasks.BuildCodegenCLITask
1515
import com.facebook.react.tasks.GenerateCodegenArtifactsTask
1616
import com.facebook.react.tasks.GenerateCodegenSchemaTask
1717
import java.io.File
18+
import kotlin.system.exitProcess
1819
import org.gradle.api.Plugin
1920
import org.gradle.api.Project
2021
import org.gradle.api.Task
22+
import org.gradle.internal.jvm.Jvm
2123

2224
class ReactPlugin : Plugin<Project> {
2325
override fun apply(project: Project) {
26+
checkJvmVersion()
2427
val extension = project.extensions.create("react", ReactExtension::class.java, project)
2528
applyAppPlugin(project, extension)
2629
applyCodegenPlugin(project, extension)
2730
}
2831

32+
private fun checkJvmVersion() {
33+
val jvmVersion = Jvm.current()?.javaVersion?.majorVersion
34+
if ((jvmVersion?.toIntOrNull() ?: 0) <= 8) {
35+
println("\n\n\n")
36+
println(
37+
"**************************************************************************************************************")
38+
println("\n\n")
39+
println("ERROR: requires JDK11 or higher.")
40+
println("Incompatible major version detected: '" + jvmVersion + "'")
41+
println("\n\n")
42+
println(
43+
"**************************************************************************************************************")
44+
println("\n\n\n")
45+
exitProcess(1)
46+
}
47+
}
48+
2949
private fun applyAppPlugin(project: Project, config: ReactExtension) {
3050
project.afterEvaluate {
3151
if (config.applyAppPlugin.getOrElse(false)) {

react.gradle

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import org.apache.tools.ant.taskdefs.condition.Os
9+
import org.gradle.internal.jvm.Jvm
910

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

@@ -129,6 +130,19 @@ android {
129130
}
130131
}
131132

133+
def jvmVersion = Jvm.current().javaVersion.majorVersion
134+
if (jvmVersion.toInteger() <= 8) {
135+
println "\n\n\n"
136+
println "**************************************************************************************************************"
137+
println "\n\n"
138+
println "ERROR: requires JDK11 or higher."
139+
println "Incompatible major version detected: '" + jvmVersion + "'"
140+
println "\n\n"
141+
println "**************************************************************************************************************"
142+
println "\n\n\n"
143+
System.exit(1)
144+
}
145+
132146
afterEvaluate {
133147
def isAndroidLibrary = plugins.hasPlugin("com.android.library")
134148
def variants = isAndroidLibrary ? android.libraryVariants : android.applicationVariants

0 commit comments

Comments
 (0)