mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix: jvm 11 error message from ReactPlugin.kt and react.gradle (#33048)
Summary: you can see discussion here: https://github.com/reactwg/react-native-releases/discussions/13#discussioncomment-2069527 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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Andrei Shikov
parent
54f5c8c26c
commit
b1c30f8f8a
@@ -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)) {
|
||||
|
||||
@@ -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 : [:];
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user