oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.34k stars 1.63k forks source link

[Native Image] Not able to launch native App created using SWT #9810

Open shireeshakalle opened 2 weeks ago

shireeshakalle commented 2 weeks ago

Describe the Issue

I'm getting the following exception when I try to launch the native app which created using swt.

SWT version:3.126.0 JDK:21 GraalVM Version:graalvm-jdk-21.0.4+8.1

When I try to load shell = new Shell(SWT.CLOSE | SWT.MIN);I'm getting the following error. I'm passing all config files(proxy-config.json, reflect-config.json, jni-config.json, resource-config.json)

Exception in thread "main" java.lang.NoSuchFieldError: org.eclipse.swt.internal.win32.GESTURECONFIG.dwBlock at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getFieldID(JNIFunctions.java:1357) at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetFieldID(JNIFunctions.java:449) at org.eclipse.swt.internal.win32.OS.SetGestureConfig(Native Method) at org.eclipse.swt.widgets.Control.checkGesture(Control.java:692) at org.eclipse.swt.widgets.Control.createWidget(Control.java:709) at org.eclipse.swt.widgets.Scrollable.createWidget(Scrollable.java:160) at org.eclipse.swt.widgets.Decorations.createWidget(Decorations.java:375) at org.eclipse.swt.widgets.Shell.(Shell.java:318) at org.eclipse.swt.widgets.Shell.(Shell.java:281) at org.eclipse.swt.widgets.Shell.(Shell.java:207).

Can someone please help me on this!!!

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

I have tried with 1.graalvm-jdk-21.0.4+8.1, java 21 version and 2.Java 17 and graalvm-ce-java17-22.3.1.

Operating System and Version

Windows 11

Diagnostic Flag Confirmation

Run Command

just double click on native image.

Expected Behavior

it should launch an app with login credentials.

Actual Behavior

its throwing an error which is mentioned above.

Steps to Reproduce

Just create simple swt application to open dialogue box and run native image.

Additional Context

No response

Run-Time Log Output and Error Messages

No response

shireeshakalle commented 2 weeks ago

Here is the sample code to reproduce the issue.

public class SimpleShell {
    public static void main(String[] args) {
        try {
            // Create display and shell
            Display display = new Display();
            Shell shell = new Shell(display, SWT.SHELL_TRIM); // Adds min, max, and close buttons

            // Set the shell title
            shell.setText("SWT Shell with Min/Max/Close");

            // Set size and open the shell
            shell.setSize(400, 300);
            shell.open();

            // Event loop to keep shell open
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }

            // Dispose the display when shell is closed
            display.dispose();
            System.out.println("....end....");
        } catch (Exception e) {
            System.out.println("....error....");
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Please any one help me on this

oubidar-Abderrahim commented 2 weeks ago

Hi, can you please provide a complete reproducer? the example you shared is missing the imports and the dependencies needed to compile it

shireeshakalle commented 2 weeks ago

package test; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell;

public class SimpleShell { public static void main(String[] args) { try { // Create display and shell Display display = new Display(); Shell shell = new Shell(display, SWT.SHELL_TRIM); // Adds min, max, and close buttons

        // Set the shell title
        shell.setText("SWT Shell with Min/Max/Close");

        // Set size and open the shell
        shell.setSize(400, 300);
        shell.open();

        // Event loop to keep shell open
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }

        // Dispose the display when shell is closed
        display.dispose();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

org.eclipse.platform org.eclipse.swt.win32.win32.x86_64 3.126.0

Please find the sample code and SWT dependency which I have used

@oubidar-Abderrahim let me know if you need more details

shireeshakalle commented 2 weeks ago

@oubidar-Abderrahim Any update please let me know ?

shireeshakalle commented 2 days ago

@oubidar-Abderrahim Any update please let me know ,it seems like this is blocker for us so please help us to get out of this.