javafxports / javafxmobile-plugin

A gradle plugin for building mobile applications in java.
BSD 3-Clause "New" or "Revised" License
43 stars 19 forks source link

javafxmobile-plugin 2.x how to specify reflectionList? #89

Open samyc1201 opened 4 years ago

samyc1201 commented 4 years ago

I encounter some sort of reflection issue when I am using plugin 2.x version, I can't find a way to configure in gradle in order to force GraalVM to prepare reflection correctly. How can we do that in plugin 2.x?

Look like the maven plugin contain such required configuration, but how do we specify in gradle:

https://docs.gluonhq.com/client/#_reflectionlist

The error I encounter is as below:

[SUB] Fatal error, we can't find a native method called Java_jdk_internal_misc_Unsafe_staticFieldOffset0
[SUB] Fatal error, we can't find a native method called Java_jdk_internal_misc_Unsafe_staticFieldOffset0__Ljava_lang_reflect_Field_2
[SUB] error resolving native method short Java_jdk_internal_misc_Unsafe_staticFieldOffset0 long Java_jdk_internal_misc_Unsafe_staticFieldOffset0__Ljava_lang_reflect_Field_2
[SUB] java.lang.RuntimeException: Missing native symbol Java_jdk_internal_misc_Unsafe_staticFieldOffset0
[SUB]   at java.lang.Throwable.fillInStackTrace(Unknown Source)
[SUB]   at java.lang.Throwable.<init>(Unknown Source)
[SUB]   at java.lang.Exception.<init>(Unknown Source)
[SUB]   at java.lang.RuntimeException.<init>(Unknown Source)
[SUB]   at jdk.internal.misc.Unsafe.staticFieldOffset0(Unknown Source)
[SUB]   at jdk.internal.misc.Unsafe.staticFieldOffset(Unknown Source)
[SUB]   at jdk.internal.reflect.UnsafeFieldAccessorImpl.<init>(Unknown Source)
[SUB]   at jdk.internal.reflect.UnsafeStaticFieldAccessorImpl.<init>(Unknown Source)
[SUB]   at jdk.internal.reflect.UnsafeQualifiedStaticFieldAccessorImpl.<init>(Unknown Source)
[SUB]   at jdk.internal.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl.<init>(Unknown Source)
[SUB]   at jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(Unknown Source)
[SUB]   at jdk.internal.reflect.ReflectionFactory.newFieldAccessor(Unknown Source)
[SUB]   at java.lang.reflect.Field.acquireFieldAccessor(Unknown Source)
[SUB]   at java.lang.reflect.Field.getFieldAccessor(Unknown Source)
[SUB]   at java.lang.reflect.Field.get(Unknown Source)
[SUB]   at sg.com.income.dsf.quogen.utils.PdfUtils.serializeConstant(Unknown Source)
[SUB]   at sg.com.income.dsf.quogen.config.TemplateConfig.init(Unknown Source)
[SUB]   at sg.com.income.dsf.quogen.config.TemplateConfig.get(Unknown Source)
[SUB]   at sg.com.income.dsf.quogen.core.QuoGenerator.generate(Unknown Source)
[SUB]   at sg.com.income.dsf.quogen.MainProgram.main(Unknown Source)
[SUB]   at com.gluonapplication.BasicView$1.handle(Unknown Source)
[SUB]   at com.gluonapplication.BasicView$1.handle(Unknown Source)
[SUB]   at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
[SUB]   at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
[SUB]   at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)

The code that throwing error is as below:

public Map<String, Object> serializeConstant(Class classz) {
    Map<String, Object> myConstant = new HashMap<>();

    Field[] declaredFields = classz.getDeclaredField(); // guess error happen at this line

    for (Field field : declaredFields) {
        if (Modifier.isStatic(field.getModifiers)) {
            try {
                myConstant.put(field.getName(), field.get(null));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return myConstant;
}
abhinayagarwal commented 4 years ago

Hi Sam,

This issue is related to Client Maven Plugin, which is located here: https://github.com/gluonhq/client-maven-plugin

samyc1201 commented 4 years ago

actually I encounter this issue while I am using javafxmobile-plugin 2.x to build/deploy the sample project... not the client maven plugin...