javafxgluon

javafx gluon mobile : reflection classes not used


I am building a mobile gluon javafx application. App runs fine in the jvm but not on mobile.

I found out that i had ClassNotFoundException when loading the FXML and discovered that it would not find java.net.URL(!!) The unfound classes were not present in the projet arm64_ios reflection files, but i somewhat expected that as i did not directly use those classes in the code. Unfortunately, gluon seems not to be able to parse the fxml to add known classes. But i disgress.

Just to validate the problem, i added this class name to my POM reflectionList. As expected, it would find it but block on an other one, then an other one, this was endless. I check out that when i ran gluonfx:runagent, the missing classes were correctly added to src/main/resources/META-INF/native-image/reflect-config.json.

As per https://docs.gluonhq.com/#_jni_and_reflection , i added a META-INF/substrate/congif/reflectionconfig.json file that was a copy of the META-INF/native-image/reflect-config.json. That did not help.

I do not know why the runagent files are not used, i think i might have fumbled somewhere. I will be very grateful for any hint. Thanks.

Here are the relevant parts of my POM.

    <packaging>jar</packaging>
  
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>11</maven.compiler.release>
        <javafx.version>17.0.2</javafx.version>
        <attach.version>4.0.13</attach.version>
        <gluonfx.plugin.version>1.0.12</gluonfx.plugin.version>
        <javafx.plugin.version>0.0.8</javafx.plugin.version>
        <mainClassName>com.blah</mainClassName>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq</groupId>
            <artifactId>charm-glisten</artifactId>
            <version>6.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>display</artifactId>
            <version>${attach.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>lifecycle</artifactId>
            <version>${attach.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>statusbar</artifactId>
            <version>${attach.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>storage</artifactId>
            <version>${attach.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>util</artifactId>
            <version>${attach.version}</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>Gluon</id>
            <url>https://nexus.gluonhq.com/nexus/content/repositories/releases</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>${javafx.plugin.version}</version>
                <configuration>
                    <mainClass>${mainClassName}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                    </execution>
                    <execution>
                        <!-- Configuration for manual attach debugging -->
                        <!-- Usage: mvn clean javafx:run@debug -->
                        <id>debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for automatic IDE debugging -->
                        <id>ide-debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for automatic IDE profiling -->
                        <id>ide-profile</id>
                        <configuration>
                            <options>
                                <option>${profiler.jvmargs.arg1}</option>
                                <option>${profiler.jvmargs.arg2}</option>
                                <option>${profiler.jvmargs.arg3}</option>
                                <option>${profiler.jvmargs.arg4}</option>
                                <option>${profiler.jvmargs.arg5}</option>
                            </options>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>gluonfx-maven-plugin</artifactId>
                <version>${gluonfx.plugin.version}</version>
                <configuration>
                    <verbose>true</verbose>
                    <target>${gluonfx.target}</target>
                    <attachList>
                        <list>display</list>
                        <list>lifecycle</list>
                        <list>statusbar</list>
                        <list>storage</list>
                    </attachList>
                    <reflectionList>
                        <list>java.net.URL</list>
                    </reflectionList>
                    <mainClass>${mainClassName}</mainClass>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.css</include>
                    <include>**/*.png</include>
                    <include>*.png</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.css</include>
                    <include>**/*.png</include>
                    <include>*.png</include>
                </includes>
            </resource>
        </resources>
    </build>

    <profiles>
        <profile>
            <id>ios</id>
            <properties>
                <gluonfx.target>ios</gluonfx.target>
            </properties>
        </profile>
        <profile>
            <id>android</id>
            <properties>
                <gluonfx.target>android</gluonfx.target>
            </properties>
        </profile>
    </profiles>

Solution

  • Ok, now i found a solution, not sure i understood what happens.

    Everything was caused by my resources includes. Not sure why/if i added them, not sure where they came from. It seems that configuring includes removes the default ones and that forbid the inclusion of the json files, and thus i had no other defined reflections than those that were found at compilation.

    Removing the includes section of the POM and adding <nativeImageArgs>--allow-incomplete-classpath</nativeImageArgs> within the POM finally cleared all compilation blurps.

    This post helped me for this last tip: Why is my JavaFX 17 Application not building with Gluon ? Logged as JNI / Reflection problem

    Thanks José for coming by.