Java is an object-oriented programming language for creating various applications like web applications, mobile applications, desktop applications, game applications, etc. when you are working with Java, you may experience the error “accessible: module java.base does not “opens java.io” to unnamed module in Java”.
How the error shows up
When you start learning to create Android programming using Android Studio, you get the error warning all the time you try to execute and build. This is the error message you are experiencing:
Unable to make field private final java.lang.String java.io.File.path accessible: 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 @42760a00
Options To Resolve the Error “accessible: module java.base does not “opens java.io” to unnamed module in Java”
In this section, we are going to learn simple ways to handle the error warning. Check out the simplest options you can try:
Option 1 – Switch the version of the gradle to 7.1.1
To eliminate the error you are getting, switching the version of the gradle to 7.1.1 is really helpful. You need to change the version in the properties gradle-wrapper. To do that, you need to follow the below code and add it to the gradle.properties:
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
Option 2 – Replace a code in android/build.gradle
Another way to make thing works correctly is to replace a line after checking it.
With the command:
Option 3 – Use the ‘Flutter doctor’ command
If you are using an Arctic Fox version of Android Studio, you can simply use this way on Mac to fix the error. Have a look at the command you can run on Mac:
cd /Applications/Android\ Studio.app/Contents/jre ln -s ../jre jdk ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
Options 4 – Downgrade to JDK 8/ JDK 15
Another effective option you can try out to get rid of the error warning. Follow the steps:
- In the case you are using JDK version 16, you need to downgrade it to version JDK 15.
- Download JDK 8 (1.8). after this, install it with the help of the on-screen instruction.
- Next, you need to modify the environment variable (write JDK-8 path to environment variable)
- Change the structure of your project, and for the JDK location, add JDK 8 path.
- You need to clear caches.
- Restart Android Studio
- Now, you can create your project
It resolves the error warning.
And that’s how exactly you can fix the error “accessible: module java.base does not “opens java.io” to unnamed module in Java”. We have added a few effective solutions that you can try out according to the condition and status of your current project.
I hope you find it helpful! I wish you the best of luck!
If you have any queries or you want further assistance, don’t hesitate to type a comment in the comment box below.