Unable to make field private final java.lang.String java.io.File.path accessible: module java.base

Problem Description:

An error is reported when running the application with Android Studio:

Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @7a4eb222 

From the error message, it can be seen that it is related to Java modularization. JDK8 was used before, and modularization is a new function introduced by JDK9.

Solution:

After inspection, it was found that gradle7 was upgraded, and the JDK 17 used was really a big jump. I have to say that Java has released versions very quickly in recent years.

method 1:

Since JDK 17 is to be modularized, specify a JDK8 that does not require modularization with the project.

It can be set in gradle.properties (found in the project root directory)

org.gradle.java.home=/path_to_jdk8_directory

Method 2:

In order to facilitate compatibility with projects that did not use modularization, JDK has improved some configuration items. JDK17 is still used, and configuration items can be added to the gradle.properties file:

org.gradle.jvmargs=-Xmx1536M \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens=java.base/java.io=ALL-UNNAMED \
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

problem solved

おすすめ

転載: blog.csdn.net/tianlangstudio/article/details/131320269