[Fixed] getting Error: How to make field private final java.lang.String java.io.File.path accessible while running my project – Java

by
Ali Hasan
android android-studio build-error build.gradle

The Solutions:

\n

Solution 2: Customizing Gradle Settings

\n

Append the following configuration to your gradle.properties file to resolve the accessibility issue:

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

This configuration:

  • Adjust the maximum memory allocation for Gradle to 1536 MB (adjust as needed).
  • Opens the java.io module to the unnamed module.
  • Exports the sun.nio.ch, java.lang, java.lang.reflect, and sun.misc modules to the unnamed module.

Solution 3: Modifying Java Compatibility in Project Structure

The issue arises due to using a Java version (in this case, Java 17) that is not fully supported by Gradle. To resolve this, modify the Java compatibility in Project Structure:

  1. Open your project in Android Studio.
  2. Go to "Project Structure" (File > Project Structure).
  3. Select the "SDKs" tab.
  4. Ensure that the Java compiler version and language level are set to a supported version, such as Java 16 or lower.
  5. After making the changes, click "Apply" and "OK" to save your settings.

This should resolve the error and allow you to run your project successfully.

Q&A

How to run project when getting error- Error: Unable to make field private final java.lang.String java.io.File.path accessible

Download JDK 11 and check compatibility for AGL

How to add external java library to android project

Add the below line in your gradle.properties

How check Java Compatibility with Gradle

Check Java Compatibility with Gradle & then modify it in Project structure

Video Explanation:

The following video, titled "Fix 'Unable make field private final java.util.Comparator java.util ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Cucumber #Selenium #Appium #RestAssured #Automation #Error message #ExceptionInInitializerError #java.util.