27

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 @786f3609 enter image description here

5 Answers 5

38

I had the same issue and I resolved it by appending

org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED

To the file :

./android/gradle.properties
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much! I was struggling since yesterday after upgrading to the latest flutter version and then got this error. Only this solution worked!
thanks! I have no idea how we programmed back in the days without SO.
Welcome Billy, I am happy that I could help you here, it was harder obviously
23

Choose JDK Location to lower than Java 16, as it is not supported in Android studio as of now.

1 Comment

I got this when running fastlane to build an ionic project. It built manually in studio, but not from fastlane. Fix was to include this before running fastlane, to ensure correct path (on MacOS Monterey) export PATH=$HOME/.fastlane/bin:$PATH && export ANDROID_HOME=~/Library/Android/sdk && export PATH=${PATH}:${ANDROID_HOME}/tools && export PATH=${PATH}:${ANDROID_HOME}/platform-tools && export JAVA_HOME=/usr/libexec/java_home -v 11.0.15.1
21

Adding --add-opens=java.base/java.io=ALL-UNNAMED to your JAVA_OPTS environment variable or the org.gradle.jvmargs gradle property will resolve this issue with Java 18.

Here is the full org.gradle.jvmargs gradle property value that I'm using:

org.gradle.jvmargs = -Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" --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

Comments

4

This Issue occur due to :-

The error message you're seeing indicates that you are trying to access or modify a private final field (java.io.File.path) in the java.io package, but the module system is preventing such access.

How I solved this issue :-

Steps :- Click on files-> Settings -> Build, Execution and Deployment -> Build Tools -> Gradle -> Then select the jdk 11.

I used this version

Then Clean and Rebuild your project and you good to go now.

Comments

0

If you've encountered an "Invalid Keystore Format" error in Android Studio and you recently upgraded your JDK to version 20, downgrading to JDK 11 help resolve the issue. Follow these steps to get your project back on track:

  1. Uninstall Current JDK: if you've recently installed a higher version of the JDK (e.g., JDK 20), uninstall it from your system.

  2. Download JDK 11 Visit the official Oracle website and download JDK 11. Please note that JDK 11 might require an Oracle account for downloading, as it's an older version. but no worries you can create you oracle account just within 2 minutes.

  3. Install JDK 11

  4. In Search Bar of Windows Search Environment Variables and click on environment variables:

  5. In System variable Windows of Environment Variable Click on Path and Click Edit, then go to the bin directory of Java jdk folder (e.g., C:\Program Files\Java\jdk-11\bin). Copy this path and paste below previous paths. In the same environment variables window, click on NEW in system variable in name enter JAVA_HOME and set its value to the JDK 11 home directory (e.g., C:\Program Files\Java\jdk-11).

  6. Now go to your android studio project

  7. Go to "File" > "Project Structure."

  8. in Gradle Settings Select the JDK 11, as you installed and added to environment variable so it will appear there.

  9. Rebuild your project adn you're good to go.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.