javaandroidfluttergradlebuild

How to suppress "Restricted method called: java.lang.System::load" warning when using native-platform in Gradle on JDK 22+


I'm working with Gradle 8.12 and Java 22, and I'm encountering the following warning during build:

WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by net.rubygrapefruit.platform.internal.NativeLibraryLoader...
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning...
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

I understand this relates to Java's native access restrictions introduced in newer JDKs. I'm trying to silence the warning by setting:

--enable-native-access=ALL-UNNAMED

However, I'm unsure of the best way to add this JVM argument to Gradle. Should it go in gradle.properties, as an environment variable, or somewhere else? Also, is this the recommended way for builds using native-platform?

Any guidance on where exactly to configure this in a Gradle project (and whether this approach is safe/portable) would be appreciated!


Solution

  • To enable native access for all unnamed modules in IntelliJ IDEA, which is often necessary when working with newer JDK versions and certain libraries that utilize restricted methods, the --enable-native-access=ALL-UNNAMED JVM option needs to be added to the project's or run configuration's JVM arguments.

    Steps to add the JVM argument in IntelliJ IDEA:

    Note: While --enable-native-access=ALL-UNNAMED provides broad access, for more specific control, individual modules can be listed instead of ALL-UNNAMED (e.g., --enable-native-access=M1,M2,...). This option addresses warnings and potential errors related to restricted method access in newer Java versions.