How to fix the ”module java.base does not “opens java.io” to unnamed module ” error in Android Studio?

We Are Going To Discuss About How to fix the ”module java.base does not “opens java.io” to unnamed module ” error in Android Studio?. So lets Start this Java Article.

How to fix the ”module java.base does not “opens java.io” to unnamed module ” error in Android Studio?

  1. How to fix the ''module java.base does not “opens java.io” to unnamed module '' error in Android Studio?

    The solution from GitHub has worked for me. It was no need to downgrade Java JDK. Just changed gradle version in gradle-wrapper properties to 7.1.1 (6.x does not support java 16), and adding the following line in gradle.properties:

  2. module java.base does not “opens java.io” to unnamed module

    The solution from GitHub has worked for me. It was no need to downgrade Java JDK. Just changed gradle version in gradle-wrapper properties to 7.1.1 (6.x does not support java 16), and adding the following line in gradle.properties:

Solution 1

The solution from GitHub has worked for me. It was no need to downgrade Java JDK. Just changed gradle version in gradle-wrapper properties to 7.1.1 (6.x does not support java 16), and adding the following line in 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

Original Author lortschi Of This Content

Solution 2

I found this discussion kind of related to my question.
But could not figure out how to pass JVM parameters in Android studio.

But, the error is gone after replacing JDK 16 by JDK 15.

Original Author lortschi Of This Content

Solution 3

I think I found the solution.

If you are importing an old project you are likely to face this error.

Basically you made your old project with lower JDK versions and now you have higher JDK versions installed currently in your system.

You should avoid higher JDK versions for building older projects.

  1. Basically Download JDK 8 (1.8) and install it.
  2. change environment variable (write JDK 8 path to environment variable)
  3. Then change your project structure and write JDK 8 path to JDK location.

enter image description here

  1. invalidate caches and restart android studio.
  2. build your project and it should work.

If you got the following error:

Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536

Then add the following dependency in your app.gradle file:

 // multidex
implementation 'com.android.support:multidex:1.0.3'

then you need to enable multidex in your app.gradle file.

android {
compileSdkVersion 30

defaultConfig {
    applicationId "com.convenient.easymeasure"
    minSdkVersion 19
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"
    multiDexEnabled true

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Original Author Meraj Of This Content

Solution 4

You must be using a JDK version that is not supported by the Gradle Version.

1-Check your JDK Version ( There is no need to downgrade )

2-Check The Respective Gradle version for your JDK
https://docs.gradle.org/current/userguide/compatibility.html

3-Open gradle-wrapper.properties from .\android\gradle\wrapper\
Screen Shot for gradle-wrapper.properties file and change the distributionUrl to your required gradle version

e.g. for JDK 17

distributionUrl = https\://services.gradle.org/distributions/gradle-7.3-all.zip

4-Open build.gradle from .\android\build.gradle
classpath in build.gradle file
and change the plugin in the class path to the one according to your gradle version

e.g.

classpath("com.android.tools.build:gradle:4.2.2") for JDK 6.71+
classpath("com.android.tools.build:gradle:7.0.0") for JDK 7+

Check the Compatible Plugin for your Gradle version at
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle

5-run npx react-native run-android

Original Author usamayaseen Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment