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

React Native is not compatible with JDK 18 #34103

Closed
cortinico opened this issue Jun 29, 2022 · 13 comments
Closed

React Native is not compatible with JDK 18 #34103

cortinico opened this issue Jun 29, 2022 · 13 comments
Labels
Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Priority: Low Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@cortinico
Copy link
Contributor

cortinico commented Jun 29, 2022

Description

I'm opening this issue for the sake of visibility/transparency.

We received multiple reports of users on JDK 18 not being able to build app for Android using the New Architecture

I did a small investigation on the JDK 18 support.

There are a couple of things to note here:

  1. Gradle don't formally support JDK 18 (https://docs.gradle.org/current/userguide/compatibility.html) as of today. The first version supporting it will be Gradle 7.5 (currently in RC).
  2. I've tried the RC, but it still crashes. I believe the problem might be somewhere in the JDK standard libraries or in how we use it. There seems to be a memory leak somewhere. It's curious that this happens only on JDK 18 (and not on 17).
  3. It would be interesting to try this on either a non-zulu or non-aarch64 jdk to understand if the problem is in the JDK distribution.
    That's the JDK I was using:
openjdk version "18.0.1" 2022-04-19
OpenJDK Runtime Environment Zulu18.30+11-CA (build 18.0.1+10)
OpenJDK 64-Bit Server VM Zulu18.30+11-CA (build 18.0.1+10, mixed mode, sharing)
  1. Having a heapdump of the crash would also be helpful. As the app instacrash, that's a bit tricky to do. I haven't managed to do this yet.

Version

0.68.0

Stacktrace

Error reporting crash
java.lang.OutOfMemoryError: Failed to allocate a 320848968 byte allocation with 4742061 free bytes and 187MB until OOM, target footprint 9582429, growth limit 201326592
	at java.util.Arrays.copyOf(Arrays.java:3257)
	at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:448)
	at java.lang.StringBuilder.append(StringBuilder.java:137)
	at java.lang.Throwable.toString(Throwable.java:493)
	at java.lang.String.valueOf(String.java:2924)
	at java.io.PrintWriter.println(PrintWriter.java:754)
	at java.lang.Throwable$WrappedPrintWriter.println(Throwable.java:778)
	at java.lang.Throwable.printStackTrace(Throwable.java:667)
	at java.lang.Throwable.printStackTrace(Throwable.java:735)
	at android.app.ApplicationErrorReport$CrashInfo.<init>(ApplicationErrorReport.java:354)
	at android.app.ApplicationErrorReport$ParcelableCrashInfo.<init>(ApplicationErrorReport.java:484)
	at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:157)
	at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1073)
	at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
	at java.lang.Thread.dispatchUncaughtException(Thread.java:2200)asdf
@cortinico cortinico added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Jun 29, 2022
@cortinico cortinico added Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Priority: Low and removed Needs: Triage 🔍 labels Jun 29, 2022
@leotm
Copy link
Contributor

leotm commented Jun 29, 2022

as an aside also spotted CPU/memory leak w Gradle 7.6 nightly bout month ago in CI w JDK 18

edit: nvm think was forgetting to clean between Debug/Release at the time, closing for now

@leotm
Copy link
Contributor

leotm commented Jun 29, 2022

initially took the ain't going near that sh!t mentality, but thx for the writeup i've been inspired again, will investigate and report back as per usual x)

@leotm
Copy link
Contributor

leotm commented Jun 29, 2022

and hopefully can figure smth simpler - how to submit an issue again on Google Issue Tracker (its been few yrs) not needed

@leotm
Copy link
Contributor

leotm commented Jul 9, 2022

seems fine w AGP 7.2.1 (AGP 7.2.0 still causing the runtime error)

unsure which commit yet, can still check non-aarch64 if needed
so think can pick it into RN 0.69+ when appropriate (noting low priority)

@mikehardy
Copy link
Contributor

still requires gradle 7.5+ though right? Which just released like, yesterday?

@leotm
Copy link
Contributor

leotm commented Jul 15, 2022

good point i don't think quite requires gradle 7.5+
7.4.2 debug/release builds/runtime still fine for me on Zulu18
(could still make sure on non-zulu's and aarch32's)

@leotm
Copy link
Contributor

leotm commented Jul 15, 2022

but yh now looks time to bump to 7.5 stable for official/full JDK 18 support (by full, not jus AGP bump to 7.2.1)
then provided the 20ish ci tests pass 🤞

Gradle now checks the Adoptium API first when downloading JDKs, rather than only using the legacy AdoptOpenJDK API. This allows downloading the new JDK 18 releases, which are not available via AdoptOpenJDK, while still maintaining the ability to download versions that are no longer supported by Adoptium, such as JDK 9-10 and 12-16.

https://docs.gradle.org/7.5/release-notes.html#jvm-toolchains-improvements
then also jdk related commits there, seems more related to downloading JDK 18 not via brew?
again i'm not from android bg jus making sense of things

i'm going to check/run locally soon, debug/release builds looking good

@cortinico
Copy link
Contributor Author

still requires gradle 7.5+ though right? Which just released like, yesterday?

Just for sanity check: I'd like to bump Gradle to 7.5 to make sure the next version is JDK 18 compatible. Feel free to send a PR over and ping me there for a review :)

facebook-github-bot pushed a commit that referenced this issue Aug 1, 2022
Summary:
### Follow-up
- #34103
- #33823

#### Debug/Release further tested on RN 0.70.0-rc.0-1
- leotm/react-native-template-new-architecture#775
- builds/runtime: locally on `macos-13` b2
- builds: in CI `ubuntu-20.04` latest (not yet beta `ubuntu-22.04`)

cc cortinico dulmandakh

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Changed] - Bump Gradle to 7.5.0

Pull Request resolved: #34310

Test Plan: Everything builds and runs as expected.

Reviewed By: cipolleschi

Differential Revision: D38311861

Pulled By: cortinico

fbshipit-source-id: c4e9e7a9052a067ffabae87204d20190ef46b351
kelset pushed a commit that referenced this issue Aug 3, 2022
Summary:
### Follow-up
- #34103
- #33823

#### Debug/Release further tested on RN 0.70.0-rc.0-1
- leotm/react-native-template-new-architecture#775
- builds/runtime: locally on `macos-13` b2
- builds: in CI `ubuntu-20.04` latest (not yet beta `ubuntu-22.04`)

cc cortinico dulmandakh

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Changed] - Bump Gradle to 7.5.0

Pull Request resolved: #34310

Test Plan: Everything builds and runs as expected.

Reviewed By: cipolleschi

Differential Revision: D38311861

Pulled By: cortinico

fbshipit-source-id: c4e9e7a9052a067ffabae87204d20190ef46b351
roryabraham pushed a commit to Expensify/react-native that referenced this issue Aug 17, 2022
Summary:
### Follow-up
- facebook#34103
- facebook#33823

#### Debug/Release further tested on RN 0.70.0-rc.0-1
- leotm/react-native-template-new-architecture#775
- builds/runtime: locally on `macos-13` b2
- builds: in CI `ubuntu-20.04` latest (not yet beta `ubuntu-22.04`)

cc cortinico dulmandakh

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Changed] - Bump Gradle to 7.5.0

Pull Request resolved: facebook#34310

Test Plan: Everything builds and runs as expected.

Reviewed By: cipolleschi

Differential Revision: D38311861

Pulled By: cortinico

fbshipit-source-id: c4e9e7a9052a067ffabae87204d20190ef46b351
roryabraham pushed a commit to Expensify/react-native that referenced this issue Aug 17, 2022
Summary:
### Follow-up
- facebook#34103
- facebook#33823

#### Debug/Release further tested on RN 0.70.0-rc.0-1
- leotm/react-native-template-new-architecture#775
- builds/runtime: locally on `macos-13` b2
- builds: in CI `ubuntu-20.04` latest (not yet beta `ubuntu-22.04`)

cc cortinico dulmandakh

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Changed] - Bump Gradle to 7.5.0

Pull Request resolved: facebook#34310

Test Plan: Everything builds and runs as expected.

Reviewed By: cipolleschi

Differential Revision: D38311861

Pulled By: cortinico

fbshipit-source-id: c4e9e7a9052a067ffabae87204d20190ef46b351
@varemenos
Copy link

varemenos commented Mar 13, 2023

Sorry for reviving this thread but is there no way to setup and utilize gradle toolchains?

My knowledge of Android and gradle is very limited but based on what little I understand, this should make it so gradle is using a specific version of Java specified in the config and therefore not have an expectation from the user to download and set up the "right" version of Java locally, right?

The latest version of RN utilizes gradle android plugin 7.3.1 and support for toolchains was included in 7.3 based on the comment here.

I've added the following bit to my android/app/build.gradle and run the app and it worked fine but I'm not sure if it actually did anything or it was a placebo.

java {
  toolchain {
    languageVersion = JavaLanguageVersion.of(17)
    vendor = JvmVendorSpec.ADOPTIUM
  }
}

@muhammadalizkhan
Copy link

I am Using java 19+ with Gradle 7.6 Facing Same Issue

@muhammadalizkhan
Copy link

Which version of Java and Gradle i use for React-Native?

@cortinico
Copy link
Contributor Author

The recommended version is Java 17

@muhammadalizkhan
Copy link

muhammadalizkhan commented Jul 28, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Priority: Low Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants