我刚刚在 Windows 7 机器上安装了 Gradle 2.11,当我运行 gradle -v 时,我收到一条失败消息。 Gradle 在路径中并且 dll 存在。
$ gradle -v --stacktrace
FAILURE: Build failed with an exception.
* What went wrong:
Failed to load native library 'native-platform.dll' for Windows 7 amd64.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
net.rubygrapefruit.platform.NativeException: Failed to load native library 'nati ve-platform.dll' for Windows 7 amd64.
at net.rubygrapefruit.platform.internal.NativeLibraryLoader.load(NativeL ibraryLoader.java:49)
at net.rubygrapefruit.platform.Native.init(Native.java:55)
at org.gradle.internal.nativeintegration.services.NativeServices.initial ize(NativeServices.java:74)
at org.gradle.internal.nativeintegration.services.NativeServices.initial ize(NativeServices.java:60)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute( CommandLineActionFactory.java:203)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute( CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep ortingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep ortingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots trap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j ava:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:1012)
at net.rubygrapefruit.platform.internal.NativeLibraryLocator.find(Native LibraryLocator.java:39)
at net.rubygrapefruit.platform.internal.NativeLibraryLoader.load(NativeL ibraryLoader.java:41)
... 16 more
最佳答案
这是由 Windows 配置引起的,可能是通过组策略引起的。文件 native-platform.dll 是从其中一个 JAR 文件中提取的,可能位于用户主目录的文件夹中,例如 c:\Users\%USERNAME%\Local Settings\Temp。为了保护恶意软件,可以禁用从 TMP 目录加载 DLL 和执行程序。
我遇到了具有相同症状的问题,在某些情况下,我已经能够通过将 TEMP 和 TMP 环境变量设置为指向用户目录之外(例如 c:\tmp)来解决该问题。这不是一个通用的解决方案,也不适用于 gradle。可以通过将 GRADLE_OPTS 设置为指向所需位置来覆盖 Gradle 提取 DLL 的位置。这可能对您有用:
C:\mkdir C:\tmp
C:\set GRADLE_OPTS="-Dorg.gradle.native.dir=/tmp"
关于dll - Gradle 异常无法加载 native 库 native-platform.dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36429504/