JavaFX应用iOS运行报错:java.lang.UnsatisfiedLinkError(找不到webview)
JavaFX应用在iOS模拟器/真机中白屏并抛出UnsatisfiedLinkError异常
我的JavaFX应用在Android、Linux、Mac平台运行正常,但在iOS模拟器中仅显示白屏,终端抛出java.lang.UnsatisfiedLinkError: no webview in java.library.path异常,未使用Java模块。
完整异常堆栈
Exception in Application start method [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] Exception in thread "main" java.lang.RuntimeException: Exception in Application start method [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at java.lang.Thread.run(Thread.java:833) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] Caused by: java.lang.UnsatisfiedLinkError: no webview in java.library.path [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:132) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at java.lang.ClassLoader.loadLibrary(ClassLoader.java:47) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at java.lang.Runtime.loadLibrary0(Runtime.java:818) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at java.lang.System.loadLibrary(System.java:1989) [Thu Sept 15 14:43:27 CEST 2022][INFO] [SUB] at javafx.scene.web.WebView.<clinit>(WebView.java:112)
Android环境下正常运行的pom.xml配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.xxxx.xxxx</groupId> <artifactId>xxxxxxxx</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> <maven.compiler.release>11</maven.compiler.release> <javafx.version>19</javafx.version> <attach.version>4.0.15</attach.version> <gluonfx.plugin.version>1.0.15</gluonfx.plugin.version> <javafx.plugin.version>0.0.8</javafx.plugin.version> <mainClassName>com.xxx.xxxx.xxxxx.App</mainClassName> </properties> <dependencies> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>${javafx.version}</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-web</artifactId> <version>${javafx.version}</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-fxml</artifactId> <version>${javafx.version}</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> <dependency> <groupId>com.gluonhq.attach</groupId> <artifactId>keyboard</artifactId> <version>${attach.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>11</release> </configuration> </plugin> <plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>${javafx.plugin.version}</version> <executions> <execution> <!-- Default configuration for running --> <!-- Usage: mvn clean javafx:run --> <id>default-cli</id> <configuration> <mainClass>${mainClassName}</mainClass> </configuration> </execution> </executions> </plugin> <plugin> <groupId>com.gluonhq</groupId> <artifactId>gluonfx-maven-plugin</artifactId> <version>${gluonfx.plugin.version}</version> <configuration> <target>${gluonfx.target}</target> <verbose>true</verbose> <attachList> <list>display</list> <list>lifecycle</list> <list>statusbar</list> <list>keyboard</list> <list>storage</list> </attachList> <reflectionList> <list>com.xxx.xxx.xxxxxx.xxxxxxxxx</list> </reflectionList> <mainClass>${mainClassName}</mainClass> <releaseConfiguration> <bundleName>xxxx</bundleName> </releaseConfiguration> </configuration> </plugin> </plugins> </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> <profile> <id>ios-sim</id> <properties> <gluonfx.target>ios-sim</gluonfx.target> </properties> </profile> </profiles> </project>
已尝试的解决操作
- Java版本:11、17
- GraalVM版本:11、17
- JavaFX版本:18、19
- 测试环境:iOS模拟器、iOS真机
- 构建命令:
mvn -Pios-sim clean gluonfx:runagent gluonfx:build gluonfx:package gluonfx:install gluonfx:nativerun
可行解决步骤
升级GluonFX插件版本
检查GluonFX与JavaFX版本的兼容性,将gluonfx-maven-plugin升级到最新稳定版,确保iOS平台的WebView原生库支持完整。补充WebView相关反射配置
GraalVM原生镜像需要明确的反射规则,即使使用runagent也可能遗漏WebView相关类,手动添加到<reflectionList>:<reflectionList> <list>com.xxx.xxx.xxxxxx.xxxxxxxxx</list> <list>javafx.scene.web.WebView</list> <list>javafx.scene.web.WebEngine</list> <list>com.sun.webkit.WebPage</list> </reflectionList>替换为Gluon Attach Browser服务
如果原生WebView问题无法解决,改用Gluon针对移动平台优化的Browser服务:- 添加依赖:
<dependency> <groupId>com.gluonhq.attach</groupId> <artifactId>browser</artifactId> <version>${attach.version}</version> </dependency> - 代码中调用:
BrowserService.create().ifPresent(service -> { service.showWebView("https://your-url.com"); });
- 添加依赖:
清理构建缓存
删除target/gluonfx目录后重新执行构建命令,避免缓存导致的依赖缺失问题。
内容的提问来源于stack exchange,提问作者SamFX
相关产品推荐
相关产品推荐

