gluonhq / gluonfx-gradle-plugin

Plugin that simplifies using Gluon Client for Java/JavaFX gradle projects
BSD 3-Clause "New" or "Revised" License
100 stars 21 forks source link

Issue with compiling on Linux with webview #187

Open Carlito1781 opened 7 months ago

Carlito1781 commented 7 months ago

Current Platform: Ubuntu 22.04.4 LTS 64bit

I'm encountering some issues while building my native Client using Gluon (Linux). I believe the problem lies with the webview, but I'm uncertain about how to resolve it. It compiles fine on Windows and functions properly, but I had to include the webview.dll (tried webview.so (or whatever the so webkit is on linux) alongside the executable.

Here is the error log:

[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Main
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.sun.javafx.application.PlatformImpl startup
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @71c7db30'
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.graalonline.apps.remotecontrol.FXRunner$1 lambda$flushBuffer$0
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: Exception in Application start method
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.graalonline.apps.remotecontrol.FXRunner$1 lambda$flushBuffer$0
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.graalonline.apps.remotecontrol.FXRunner$1 lambda$flushBuffer$0
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.graalonline.apps.remotecontrol.FXRunner$1 lambda$flushBuffer$0
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.graalonline.apps.remotecontrol.FXRunner$1 lambda$flushBuffer$0
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: at java.lang.Thread.run(Thread.java:833)
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.graalonline.apps.remotecontrol.FXRunner$1 lambda$flushBuffer$0
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.graalonline.apps.remotecontrol.FXRunner$1 lambda$flushBuffer$0
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] Apr 08, 2024 11:36:22 PM com.graalonline.apps.remotecontrol.FXRunner$1 lambda$flushBuffer$0
[Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: Caused by: java.lang.UnsatisfiedLinkError: com.sun.webkit.WebPage.twkInitWebCore(ZZZ)V [symbol: Java_com_sun_webkit_WebPage_twkInitWebCore or Java_com_sun_webkit_WebPage_twkInitWebCore__ZZZ]

Here is gradle

import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

plugins {
    id("com.gluonhq.gluonfx-gradle-plugin") version("1.0.21")
    id("org.openjfx.javafxplugin") version("0.1.0")
    id("com.github.johnrengelman.shadow") version("8.1.1")
    id("java")
    id("application")
    id("idea")
}

application {
    mainClass = 'com.graalonline.apps.remotecontrol.FXRunner'
}

repositories {
    mavenCentral()
    gradlePluginPortal()
    google()
    mavenCentral()
    mavenLocal()
    maven {
        url("https://oss.sonatype.org/content/repositories/snapshots/")
    }
    maven {
        url "https://nexus.gluonhq.com/nexus/content/repositories/releases"
    }
    maven { url 'https://jitpack.io' }
}

applicationName = 'RemoteControlFX'
group = 'com.graalonline.apps'
mainClassName = 'com.graalonline.apps.remotecontrol.FXRunner'
version = '1.0'

compileJava.options.encoding = 'UTF-8'
System.setProperty('file.encoding', 'UTF-8')

OperatingSystem os = DefaultNativePlatform.currentOperatingSystem
gluonfx {
    appIdentifier = applicationName

    if (os.isWindows()) {
        graalvmHome = GRAALVM_WINDOWS_HOME
    } else if (os.isLinux()) {
        graalvmHome = GRAALVM_LINUX_HOME
    } else if (os.isMacOsX()) {
        graalvmHome = GRAALVM_MACOSX_HOME
    }

}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

nativeBuild {
    if (os.isWindows()) {
        applicationDefaultJvmArgs = [
                "-Djava.home=" + gluonfx.graalvmHome,
                "-Djava.awt.headless=true",
                "-Dfile.encoding=UTF-8",
                "-H:+AllowIncompleteClasspath",
                "-H:-IncludeMethodsData",
                "--no-fallback",
                "--enable-http",
                "--enable-https",
                "--allow-incomplete-classpath",
                "--static"
        ]
    } else if (os.isLinux()) {
        applicationDefaultJvmArgs = [
                "-Djava.home=" + GRAALVM_LINUX_HOME,
                "-Djava.awt.headless=true",
                "-Dfile.encoding=UTF-8",
                "-Dprism.verbose=true",
                "-Djavafx.verbose=true",
                "--report-unsupported-elements-at-runtime",
                "-H:+AllowIncompleteClasspath",
                "-H:-IncludeMethodsData",
                "-H:+ReportExceptionStackTraces",
                "-H:+PrintAnalysisCallTree",
                "--initialize-at-build-time=com.sun.javafx.PlatformUtil",
                "--no-fallback",
                "--enable-http",
                "--enable-https",
                "--allow-incomplete-classpath",
                "--static"
        ]
    }
}

nativeBuild {

}

javafx {
    version = '21'
    modules = ['javafx.base', 'javafx.controls', 'javafx.fxml', 'javafx.web', 'javafx.media', 'javafx.swing', 'javafx.graphics']
}

dependencies {
    String osSuffix = getOSSuffix() // Custom method to determine OS suffix
    runtimeOnly("com.google.flogger:flogger-system-backend:0.5.1")

    // SubstrateVM features
    compileOnly 'org.graalvm.nativeimage:svm:22.1.0'

    //SWT for Native tools
    implementation "org.eclipse.platform:org.eclipse.swt.$osSuffix:3.124.200"

    //File Browser
    implementation  'org.jsoup:jsoup:1.17.2'
    implementation 'com.googlecode.soundlibs:tritonus-share:0.3.7-1'

    // Reactor
    implementation 'io.projectreactor:reactor-core:3.6.3'

    // SLF4j logging
    implementation 'org.slf4j:slf4j-api:2.0.7'
    implementation 'org.slf4j:slf4j-simple:2.0.7'

    // JNA
    implementation 'net.java.dev.jna:jna:5.13.0'
    implementation 'net.java.dev.jna:jna-platform:5.13.0'

    // ACE Code Editor
    implementation 'com.github.orange451:AceFX:main-SNAPSHOT'

    // Apache Mina
    implementation 'org.apache.mina:mina-core:2.2.2'

    // JavaFX
    implementation 'com.jfoenix:jfoenix:9.0.10'

    // Ikonli
    implementation 'org.kordamp.ikonli:ikonli-javafx:12.3.1'
    implementation 'org.kordamp.ikonli:ikonli-materialdesign2-pack:12.3.1'
    implementation 'io.github.mkpaz:atlantafx-base:2.0.1'

    //RC Core
    implementation 'com.google.flogger:flogger:0.5.1'
    implementation 'io.reactivex:rxjava:1.0.9'
    implementation 'org.apache.commons:commons-compress:1.21'
    implementation 'org.jetbrains:annotations:19.0.0'
    implementation 'com.google.code.gson:gson:2.8.9'
    implementation 'commons-codec:commons-codec:1.13'
    implementation 'commons-io:commons-io:2.7'
}

static String getOSSuffix() {
    String osName = System.getProperty("os.name").toLowerCase()
    if (osName.contains("win")) {
        return "win32.win32.x86_64"
    } else if (osName.contains("mac")) {
        return "cocoa.macosx.x86_64"
    } else if (osName.contains("linux") || osName.contains("nix")) {
        return "gtk.linux.x86_64"
    } else {
        throw new GradleException("Unsupported operating system for SWT dependency")
    }
}

jar {
    manifest {
        attributes 'Implementation-Title': applicationName,
                'Implementation-Version': version,
                'Main-Class': mainClassName,
                'Built-By': 'GraalOnline Dev Team'
    }
}

run {
    List<String> args = new ArrayList<String>() {{
        add("--module-path")
        add(System.getenv('JAVAFX_SDK') + "/lib")
        add("--add-modules")
        add("javafx.base,javafx.controls,javafx.fxml,javafx.web,javafx.media,javafx.graphics,javafx.swing")
    }}
    applicationDefaultJvmArgs = args
    jvmArgs = args

    doFirst {
        new File(project.buildDir, "/resources/main/config.properties").delete()
    }
}

configurations.configureEach {
    resolutionStrategy {
        eachDependency {
            if (requested.name.contains('${osgi.platform}')) {
                // use MacOs X86 as "osgi.platform" when computing the dependencies
                useTarget requested.toString().replace('${osgi.platform}', 'cocoa.macosx.x86_64')
            }
        }
    }
}

Pretty sure I installed on the dependencies required to compile the webengine. The application functions properly, but when attempting to load the webview after logging in, the application crashes. Removing the webview resolves the issue but it's required for the script edtiors.

The application functions properly, but when attempting to load the webview after logging in, the application crashes. Removing the webview resolves the issue.

(No it does not work even with a very basic webview, as soon as any webview is loaded application crashes).

Tried adding the .so (linux equivalent to dll) alongside the executable (this is how we got it to work on windows natively).

Feeling this is the primary culprit - Mon Apr 08 23:36:22 EDT 2024][INFO] [SUB] SEVERE: Caused by: java.lang.UnsatisfiedLinkError: com.sun.webkit.WebPage.twkInitWebCore(ZZZ)V [symbol: Java_com_sun_webkit_WebPage_twkInitWebCore or Java_com_sun_webkit_WebPage_twkInitWebCore__ZZZ]