gradle-graal icon indicating copy to clipboard operation
gradle-graal copied to clipboard

Unable to execute NativeImage

Open joaquinodz opened this issue 4 years ago • 11 comments

What happened?

I've been trying to generate a native image on my proyect but after exectuting the nativeImage task y get this error:

> Task :desktop:nativeImage FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':desktop:nativeImage'.
> Process 'command 'cmd.exe'' finished with non-zero exit value 255

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

NOTE: Using Windows OS, Gradle 5.6.4.

joaquinodz avatar Nov 19 '19 02:11 joaquinodz

Same error. The stacktrace just indicate that the problem is at NativeImageTask line 67.

Iltotore avatar Jan 25 '20 08:01 Iltotore

--info reveals a cmd script referencing "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd"
this seems to be from the Windows 7 SDK requirement referenced at #141, in this comment
I have been unable to install the Windows 7 SDK on my Windows 10 machine due to a conflict with "preview SDK versions".
This MSDN post details a workaround.
After that, native image succeeds.

sugoidogo avatar Jan 28 '20 06:01 sugoidogo

I would add following to README.md:

Preconditions when using on Windows

GraalVM needs the Microsoft Windows SDK for Windows 7 and .NET Framework 4 as well as the C compilers from KB2519277.

You can install it using chocolatey:

choco install windows-sdk-7.1 kb2519277

sugoidogo avatar Feb 04 '20 09:02 sugoidogo

I have the same "non-zero exit value 255" error. Which basicly says that my Java application can't run. If there is a dependency on the OS SDK (specific version) for the "nativeImage" of the Graal plugin then I agree that it would be good to add that to the readme.

Here is the SDK Archive for Windows: https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/

I installed the SDK but still have this error. This maybe because I'm using Spring Boot. The main class is the start class which is configured in Gradle like this:

springBoot { mainClassName = 'org.myorg.main.myApp' }

However the main class (in the Manifest) is org.springframework.boot.loader.JarLauncher. It doesn't matter whichI designate (the start or the main class) it fails with the same error.

assimbly avatar Mar 24 '20 09:03 assimbly

@assimbly my comments list multiple options for installers that fix your issue. Please read before you post.

sugoidogo avatar Mar 24 '20 19:03 sugoidogo

What do you mean exactly with that comment? I have used the command line:

choco install windows-sdk-7.1 kb2519277

Everything like SDK7.1 .Net4 and C compilers are installed (no warning/errors in the installer). Because I have multiple SDKs I used the following command:

call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x86

However I still have the same error message (ERROR: The system was unable to find the specified registry key or value. ♀Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7. 1. Targeting Windows 7 x86 Release). There is an article about that:

https://stackoverflow.com/questions/22188919/windows-sdk-registry-variable-not-found

When checking the SDK directory and regedit value everything seems to be OK.

assimbly avatar Mar 24 '20 20:03 assimbly

Your original comment does not mention any of the steps I posted and has a small amount of incorrect/redundant information. If you followed the previous instructions then please include that in your post so people don't think you're ignoring them.

This plugin calls the correct setenv by itself, regardless of how many sdks you have installed, because the path is hardcoded. If you are calling setenv before gradle nativeimage then that may be your issue. You can also try running with --info or the other flags suggested by Gradle when a command fails in order to diagnose. Either way, it sounds like you're having a separate issue. If you need more help, please open a new issue.

sugoidogo avatar Mar 24 '20 21:03 sugoidogo

Hey everyone, I was trying to use this plugin on Windows 10, and I get the same error.

The syntax of the command is incorrect.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':nativeImage'.
> Process 'command 'cmd.exe'' finished with non-zero exit value 255

Stacktrace:

Caused by: org.gradle.process.internal.ExecException: Process 'command 'cmd.exe'' finished with non-zero exit value 255
	at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:417)
	at org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:38)
	at org.gradle.process.internal.DefaultExecActionFactory.exec(DefaultExecActionFactory.java:152)
	at org.gradle.api.internal.project.DefaultProject.exec(DefaultProject.java:1135)
	at com.palantir.gradle.graal.NativeImageTask.nativeImage(NativeImageTask.java:67)

Any help is appreciated.

adityathakur-ast avatar Apr 11 '20 21:04 adityathakur-ast

@adityathakur-ast have you tried this: https://github.com/palantir/gradle-graal/issues/234#issuecomment-579096213 , https://github.com/palantir/gradle-graal/issues/234#issuecomment-581827321
If you have, please mention that when you ask for help. If you haven't, please read the thread before asking for help.

sugoidogo avatar Apr 12 '20 04:04 sugoidogo

Hi @josephsmendoza

Apologies for not being clear earlier, I have gone through your comments, but I would like to avoid a work-around, so I used "Ubuntu on Windows" which seems to work at this particular step but fails at later stage due to lack of support for graalvm 19.3+ versions.

Just to be more clear, I have checked that there is an existing PR for that, if possible, I would like to help with two things here :

  1. Windows 10 support without workaround, if possible please guide me a direction where should I look.
  2. Adding support for recent graalvm version.

adityathakur-ast avatar Apr 12 '20 07:04 adityathakur-ast

Let me clarify, in case it wasn't obvious, that the Windows 7 SDK is not a workaround. It is a requirement for building a native image on windows with this plugin. You could install a newer Windows SDK and GraalVM, call setenv or vcvars, and then run native-image manually. But for this plugin to work (currently) you need the Windows 7 SDK. You will only need the workaround on a Windows 10 machine if the Windows 7 SDK fails to install.

sugoidogo avatar Apr 12 '20 08:04 sugoidogo