Background
- I started my first project in android studio to get familiar with Android programming.
- I am following this tutorial, in which
- I created a new project Empty Activity, without any change
- It is supposed to simulate a simple app that shows "Hello World" message
Problem Description But every time I try to run and build (I want to emulator as of now), I get the following error message.
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 Here is my config set-up:
- Android Gradle plugin version: 4.2.1
- Gradle Version: 7.0.1 (changed to fix another issue I had while syncing the Gradle ("Gradle sync failed: Unsupported class file major version 60") and based discussion on this forum as quoted below)
Andrey Dernov commented 14 Apr 2021 00:18 Please use Gradle 7.0 or JDK less than 16 version for importgin and building the project (Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Gradle JVM option).
- JDK: 16.0.1
Any suggestion or idea?
029 Answers
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= \ --add-opens= \ --add-opens= \ --add-opens= \ --add-exports= 12You must be using a JDK version that is not supported by the Gradle Version. ( There is no need to downgrade )
1-Check your JDK Version from C:\Program Files\Java. In My Case, It's JDK-17.0.2
2-Check The Respective Gradle version for your JDK
3-Open gradle-wrapper.properties from .\android\gradle\wrapper\
and change the distributionUrl to your required gradle version
e.g. for JDK 17
distributionUrl = https\:// 4-Open build.gradle from .\android\build.gradle
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 Gradle 6.7.1+ classpath("com.android.tools.build:gradle:7.0.0") for Gradle 7+ Check the Compatible Plugin for your Gradle version at
5-run npx react-native run-android
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.
- Basically Download JDK 8 (1.8) and install it.
- change environment variable (write JDK 8 path to environment variable)
- Then change your project structure and write JDK 8 path to JDK location.
- invalidate caches and restart android studio.
- 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" } has worked for me in Macbook Air M1 Apple Silicon. you no need to downgrade or uninstall Java JDK.
in my case Just changed gradle version in gradle-wrapper.properties to 7.2 like this :
distributionUrl=https\:// and adding the following line in gradle.properties:
org.gradle.jvmargs=-Xmx1536M --add-exports= --add-opens= --add-opens= --add-opens= --add-exports= related solution on github
Run Flutter doctor, if there´s an error indicating that the java bundled can´t be found (specially if you have Android Studio version Artic Fox), run this commands if using Mac:
- cd /Applications/Android\
- ln -s ../jre jdk
- ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
Add this line in your gradle.properties file.
org.gradle.jvmargs=-Xmx1536M --add-exports= --add-opens= --add-opens= --add-opens= --add-exports= 1I was able to fix it by upgrading grade project settings using Android Studio which replaced classpath("com.android.tools.build:gradle:4.2.2") with classpath('com.android.tools.build:gradle:7.0.3') in android/build.gradle
In my case the following steps did the trick:
- Changing the gradle verion in gradle-wrapper.properties to:
distributionUrl=https\:// - Changing build gradle and google services classpath version in build.gradle to:
dependencies { classpath 'com.android.tools.build:gradle:7.2.1' classpath 'com.google.gms:google-services:4.3.5' }
For those having these issues with the latest Android Studio - Electric Eel version, and other canaries and preview releases, note that the bundled jre directory in the Android Studio installation folder is now renamed to jbr
(This answer came from eja's answer on this question.)
To resolve this, just create a sym link jre -> jbr and Flutter won't complain.
On Linux
cd ~/android-studio/ && ln -s jbr jre Windows (check installation folder)
cd C:\Program Files\Android\Android Studio mklink /D "jre" "jbr" or
New-Item -ItemType SymbolicLink -Path .\jre -Target .\jbr Mac OS
cd /Applications/Android\ ln -s jbr jre Note that if you are running a preview release, the default installation directory might be different, e.g. on Linux it would be
~/android-studio-preview/ In my case, my error was happened when I'm using:
Gradle version = 6.5 & Gradle JDK version = 17.0.6 in Android Studio Giraffe (Stable)
You could check the Gradle version in the gradle-wrapper.properties file, on this line:
distributionUrl=https\://
And check JDK version on:
File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK
To fix this error, you need to pick JDK version that is compatible with your Gradle Version. You could check the compatibility in here:
I pick
JDK 11.0.18forGradle version 6.5(a lower JDK version compared to my current JDK)
In summary, choosing the compatible JDK version is the answer for this error.
1I had the same issue with a Flutter 2 project after updating Android Studio to electric eel. I was still able to build the android project, but flutter run on the Flutter project would cause this issue. lortschi's answer was the key, but it was missing one more entry to make it work, so my final gradle.properties looks like this now:
org.gradle.jvmargs=-Xmx1536M \ --add-exports= \ --add-opens= \ --add-opens= \ --add-opens= \ --add-exports= \ --add-opens= android.useAndroidX=true android.enableJetifier=true I was very skeptical, but it worked.
This is a known issue by Gradle when running tests with Java 17 with Test Distribution enabled
Add this to your build.gradle (.kts version available at the link below)
tasks.named('test', Test) { jvmArgs( '--add-opens', ' '--add-opens', ' ) } 1I downloaded 2 JDK jdk-17.0.1 and jdk-11.0.13 and add below line on gradle.properties
org.gradle.java.home=C\:\\Program Files (x86)\\Java\\jdk-11.0.13 Also go to Android Studio (Arctic Fox)-> Project Structure -> Gradle setting and choose JDK version
1If you are importing an old project you may get this error
- Download JDK 8 (1.8) and install it.
- Change your project structure and write JDK 8 path to the JDK location.
some screenshots for reference (Android Studio Flaming version) (sorry, couldn't em images)
SDK location -> Gradle Settings
Gradle JDK choose download JDK
After download choose gradle jdk to 1.8
2This is a known issue when using Gson and reflection for parsing Json. Updating your Android Gradle Plugin version to 7.0.0+ and the error should go away.
Installing JDK 1.8.0 and setting JAVA_HOME path to JDK 1.8.0's folder in environment variables worked for me.
1Had same problem with Flutter. I uninstalled Android Studio and Android SDK and reinstalled everything and upgraded Flutter, without success.
Then I created a new Flutter project and copied the sources from the old one, and this time it worked.
To Flutters, just by deleting Android folder and running flutter create . on the project root fix it as well
11.ext.kotlin_version = '1.8.0'
2.replace this classpath 'com.android.tools.build:gradle:7.4.2' with your build gradle version in dependencies.
3.replace distributionUrl= in gradle wrapper properties.
I also face this issue in Android Studio after Migrating Java JDK 17
tasks.withType(Test) { jvmArgs('--add-opens=) } You must be using JDK-16, use the version below JDK-16, in my case, I downgrade to JDK-11 and it worked for me.
1Just added from another solution
If you have later version installed, and your project is using older version. Don't forget to check in terminal which jdk is used.
In my case my project using JDK 15. And terminal using 18. So i uninstall the other version and leaving the proper version (in my mac, just delete another jdk directory in /Libray/Java/JavaVirtualMachine)
Windows user:
Go to C:\Users\arpan.gradle\caches and delete all the gradle cache.
then,
Go to "C:\Program Files\Android\Android Studio" there you will see jbr and jre folder then copy the content of jbr and paste the content into jre folder. ss:
and run flutter doctor again and run your App.
I had the same problem at java 17, when I try to connect on JMS queue. It was solved adding the follow JVM options:
--add-exports= --add-opens= --add-opens= --add-opens= --add-exports= In my case, just one line was enough:
--add-opens= Downgrade your Java version.It works for me
run
sudo update-alternatives --config java and select a minor version of java .
1Steps To Solve
1. Gradle.properties
distributionUrl=https\:// 2. Java version
choose java version 17 or any compatiable
3. Gradle Project
choose kotlin version and gradle miniume version
buildscript { ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } 1Check if JDK is installed or not configure your SDK also and try again you can download JDKfrom Java SE
1Note: this is basically a solution for old project to run is successfully.
After I updated jdk to 18 then I got the error mentioned in the question. So I downgraded to jdk11, and this fixed my issue
To install jdk11 please run this command in windows 10: choco install openjdk11. Hope this will fix your problem.
To run the above command you might have to install chocolatey and add it to path environment variable. Chocolatey is a dependency manager for windows 10.
Here is link to a guide:
3