Home > Software engineering >  GluonMobile application doesn't start with JavaFX19
GluonMobile application doesn't start with JavaFX19

Time:09-19

Using the following dependencies

        <maven-compiler-plugin-version>3.10.1</maven-compiler-plugin-version>
        <maven-surefire-plugin-version>3.0.0-M6</maven-surefire-plugin-version>
        <javafx-maven-plugin-version>0.0.8</javafx-maven-plugin-version>
        <gluonfx-maven-plugin-version>1.0.14</gluonfx-maven-plugin-version>

        <java-version>17</java-version>
        <javafx-version>19</javafx-version>
        <charm-version>6.1.0</charm-version>
        <attach-version>4.0.15</attach-version>

with the template POM and graalvm-svm-java17-linux-gluon-22.1.0.1-Final, an pplication can't start if it's using new JavaFX19 API methods. for example:

public class ConsoleView extends View {

    ListView<String> console = new ListView<>();

    public ConsoleView() {
        console.setCellFactory(listView -> {
            var cell = new ListCell<String>() {

                {
                    textProperty().bind(itemProperty());
                    textFillProperty().bind(textProperty().map(text -> {
                        if (text.contains("RED")) {
                            return Color.RED;
                        } else if (text.contains("ORANGE")) {
                            return Color.ORANGE;
                        }
                        return Color.BLACK;
                    }));
                }
            };
            return cell;
        });
        setCenter(console);
        console.getItems().add("RED");
        console.getItems().add("BLUE");
        console.getItems().add("GREEN");
        console.getItems().add("ORANGE");
    }
}

compiles and builds fine (and also runs on desktop fine from the IDE), but when launching on Android the following exception occurs:

D/GraalCompiled( 4642): Exception in thread "JavaFX Application Thread" java.lang.NoSuchMethodError: javafx.beans.property.StringProperty.map(java.util.function.Function)
D/GraalCompiled( 4642):         at com.my.view.ConsoleView$1.<init>(ConsoleView.java:29)
D/GraalCompiled( 4642):         at com.my.view.ConsoleView.lambda$0(ConsoleView.java:25)
...

The method javafx.beans.property.StringProperty.map is here and is since 19. Since there is no complication and build issue, the method has to have been found. Maybe there is some issue with dynamic linking.

The documentation notes that the the JavaFX version has been bumped to 19-ea 8. Do I need to update something or wait for an update?

CodePudding user response:

The JavaFX version that you use in your pom:

<javafx-version>19</javafx-version>
<dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx-version}</version>
        </dependency>
    </dependencies>

is used by the JavaFX Maven plugin (mvn javafx:run), or by the GluonFX Maven plugin (mvn gluonfx:run) to run on your VM and that works fine.

However, when you build a native image with mvn gluonfx:build, the plugin uses the static version of the JavaFX SDK, and that is by default set by the plugin.

The GluonFX Maven plugin based on your version:

<gluonfx-maven-plugin-version>1.0.14</gluonfx-maven-plugin-version>

which is not the latest by the way (it is 1.0.15), uses the JavaFX static SDK 19-ea 8.

However, the [issue](Map, FlatMap and OrElse fluent bindings for ObservableValue) that added this new API was merged only before 19-ea 10 was released.

Until a new version of the GluonFX plugin is released with JavaFX 19 GA or the new 20-ea versions, you can simply set your plugin to use them with javafxStaticSdkVersion:

<plugin>
        <groupId>com.gluonhq</groupId>
        <artifactId>gluonfx-maven-plugin</artifactId>
        <version>${gluonfx.maven.plugin.version}</version>
        <configuration>
            <target>${gluonfx.target}</target>
            <javafxStaticSdkVersion>19</javafxStaticSdkVersion>
            <mainClass>${main.class}</mainClass>
        </configuration>
    </plugin
  • Related