简体   繁体   English

无法识别的选项:运行 cordova build android 时 --illegal-access=permit

[英]Unrecognized option: --illegal-access=permit when running cordova build android

I'm running an ionic project and I'm getting the following errors when I run ionic cordova build android :我正在运行一个 ionic 项目,当我运行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.这立即发生了,我更新了我的 ionic 版本并重新安装了 JDK 8。我的在线搜索让我明白这似乎是最近版本的cordova-android的一个非常近期的问题,并且我发现没有任何资源可以帮助解决这个问题。

Go to the path your project /platforms/android/转到您的项目路径 /platforms/android/

Edit the gradlew file编辑 gradlew 文件

Look at the end of the file in the line eval set - $ DEFAULT_JVM_OPTS and remove --illegal-access = permit查看 eval set - $ DEFAULT_JVM_OPTS 行中的文件末尾并删除--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).我在一台安装了旧版本的 Gradle (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.在安装当前的 Gradle (撰写本文时为 7.2),并将 Android 删除并重新添加到 Cordova 项目后,我能够成功构建。

This has to do with the Java Virtual Machine (JVM) version.这与 Java 虚拟机 (JVM) 版本有关。 The --illegal-access=permit option is not present int the Java 8 JVM. Java 8 JVM 中不存在--illegal-access=permit选项。 The Java 11 JVM, for example, does support it.例如,Java 11 JVM 确实支持它。

I ran into this today when running gradle init to create a gradle wrapper in my repository.我今天在运行gradle init以在我的存储库中创建一个 gradle 包装器时遇到了这个问题。 gradle init itself was successful, but the resulting gradle wrapper sets that --illegal-access=permit , which caused any ./gradlew commands I ran to fail. gradle init本身是成功的,但是生成的 gradle 包装器设置了--illegal-access=permit ,这导致我运行的任何./gradlew命令失败。

So it seems that the default gradle init task assumes that you'll be using a newer JDK version.因此,默认的gradle init任务似乎假定您将使用更新的 JDK 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM