I’m running an ionic project and I’m getting the following errors when I run ionic cordova build android
:
Unrecognized option: --illegal-access=permit
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This happened immediately I updated my ionic version and reinstalled JDK 8.My search online makes me understand it seems to be a very recent issue with recent versions of cordova-android
and no resource I found helped solve the problem.
3
Answers
Go to the path your project /platforms/android/
Edit the gradlew file
Look at the end of the file in the line eval set – $ DEFAULT_JVM_OPTS and remove –illegal-access = permit
Recompile and issue resolved
I ran into this problem on a machine that turned out to have an old version of Gradle installed (4.x). After installing current Gradle (7.2 as of this writing), and removing and re-adding Android to the Cordova project, I was able to build successfully.
This has to do with the Java Virtual Machine (JVM) version. The
--illegal-access=permit
option is not present int the Java 8 JVM. The Java 11 JVM, for example, does support it.I ran into this today when running
gradle init
to create a gradle wrapper in my repository.gradle init
itself was successful, but the resulting gradle wrapper sets that--illegal-access=permit
, which caused any./gradlew
commands I ran to fail.So it seems that the default
gradle init
task assumes that you’ll be using a newer JDK version.