Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: jvm 11 error message from ReactPlugin.kt and react.gradle #33048

Closed
wants to merge 1 commit into from

Conversation

numandev1
Copy link
Contributor

@numandev1 numandev1 commented Feb 4, 2022

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

[Android] [Fixed] - jvm 11 error message

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

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Feb 4, 2022
@react-native-bot react-native-bot added Bug Platform: Android Android applications. labels Feb 4, 2022
@analysis-bot
Copy link

analysis-bot commented Feb 4, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: cd79317
Branch: main

@analysis-bot
Copy link

analysis-bot commented Feb 4, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,120,912 +591
android hermes armeabi-v7a 7,720,886 -797
android hermes x86 8,490,376 -728
android hermes x86_64 8,442,339 -597
android jsc arm64-v8a 9,787,638 +518
android jsc armeabi-v7a 8,772,495 -876
android jsc x86 9,753,699 -812
android jsc x86_64 10,349,748 -682

Base commit: cd79317
Branch: main

@numandev1 numandev1 changed the title fix: jvm 11 error message from react-native-gradle-plugin fix: jvm 11 error message from build.gradle.kts, ReactPlugin.kt and react.gradle Feb 5, 2022
@numandev1 numandev1 force-pushed the fix/jvm-11-error branch 4 times, most recently from b92755c to eb32655 Compare February 5, 2022 20:42
@mikehardy
Copy link
Contributor

I like this as a guard rail, the only thing I don't like is that it will require maintenance going forward, now there will be 3 spots to bump the JDK version in if the requirement moves. Isn't the real requirement that JDK is > 8? So perhaps there could be an integer parse and check for > 8 vs a fixed "11. That way JDK14 and 16 etc will work with no further work?

@cortinico
Copy link
Contributor

I like this as a guard rail, the only thing I don't like is that it will require maintenance going forward, now there will be 3 spots to bump the JDK version in if the requirement moves. Isn't the real requirement that JDK is > 8? So perhaps there could be an integer parse and check for > 8 vs a fixed "11. That way JDK14 and 16 etc will work with no further work?

Agree. That's why having this inside react-native doctor was maybe a better approach.
On the other hand, if we want to add a quick warning on the Gradle side that will help people migrate to .68, that's probably the way to go

Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot more! it won't just irritatingly break in the future now, but does protect against the JDK8 past.
The only thing I can think of now is that the error message is not really consistent with the test(s) anymore. Should probably say "... requires JDK11 or higher" ?

I do think this error message will help a lot of people though, even in the much much smaller developer community that is the AnkiDroid project (maybe 20 developers?) this helped a few people. Here in react-native for 0.68 I bet this helps hundreds, most of whom probably do not know about doctor yet

@numandev1
Copy link
Contributor Author

I like this as a guard rail, the only thing I don't like is that it will require maintenance going forward, now there will be 3 spots to bump the JDK version in if the requirement moves. Isn't the real requirement that JDK is > 8? So perhaps there could be an integer parse and check for > 8 vs a fixed "11. That way JDK14 and 16 etc will work with no further work?

Agree. That's why having this inside react-native doctor was maybe a better approach. On the other hand, if we want to add a quick warning on the Gradle side that will help people migrate to .68, that's probably the way to go

@cortinico Agree, I will also make another PR for doctor CLI.

@mikehardy you are right, I am done with the changes that you told

@numandev1
Copy link
Contributor Author

I like this a lot more! it won't just irritatingly break in the future now, but does protect against the JDK8 past. The only thing I can think of now is that the error message is not really consistent with the test(s) anymore. Should probably say "... requires JDK11 or higher" ?

I do think this error message will help a lot of people though, even in the much much smaller developer community that is the AnkiDroid project (maybe 20 developers?) this helped a few people. Here in react-native for 0.68 I bet this helps hundreds, most of whom probably do not know about doctor yet

@mikehardy Thanks, I have changed the error message with ERROR: requires JDK11 or higher.

Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Near as I can tell, it's a thing of beauty! 👍

@@ -50,6 +52,19 @@ java {
targetCompatibility = JavaVersion.VERSION_11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change those two to JavaVersion.VERSION_8 otherwise the build won't even start on JDK 8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I know. users of old releases will use older versions of react-native-gradle-plugin. let me change it to JavaVersion.VERSION_1_8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cortinico with JavaVersion.VERSION_1_8 i am getting this error

Build file '/Users/apple/Data/react-native/ReactAndroid/build.gradle' line: 9

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
   > 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`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you building with JDK 11 right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cortinico I am getting this error for java 1.8. with JDK 11 it is working well. should and replaceJavaVersion.VERSION_11 withJavaVersion.VERSION_1_8, I think, we should not replace it because there is no benefit according to me what do you say?

packages/react-native-gradle-plugin/build.gradle.kts Outdated Show resolved Hide resolved
@numandev1 numandev1 changed the title fix: jvm 11 error message from build.gradle.kts, ReactPlugin.kt and react.gradle fix: jvm 11 error message from ReactPlugin.kt and react.gradle Feb 8, 2022
@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @nomi9995 in 4e947ec.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Feb 9, 2022
@numandev1 numandev1 deleted the fix/jvm-11-error branch February 9, 2022 18:26
ShikaSD pushed a commit that referenced this pull request Feb 24, 2022
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
@bozaigao
Copy link

  1. install idk 11;
  2. AndroidStudio->file->ProjectStructure->click Gradle Settings->choose idk 11 ->sync;

截屏2022-05-28 20 28 12

@facebook facebook locked as resolved and limited conversation to collaborators May 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants