我正在使用 jdk-10.0.2
和 gradle 4.7
,在构建我的项目时出现此错误。
Unable to find method 'sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
最佳答案
我有同样的问题(但使用 JDK 11
):
Unable to find method 'sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;'.
与你一样使用 gradle 4.7
版本。
我的 gradle-wrapper.properties
文件是:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
为了解决这个问题,我使用参数 distributionUrl
更改为 4.9 版本的包装器:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
并在没有任何错误的情况下重建项目。
关于java - 无法找到方法 sun.misc.Unsafe.defineClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55918972/