JavaFX ProGuard 应用程序在混淆后无法运行

JavaFX ProGuard app is not working after obfuscate

在尝试混淆我的 javaFX 应用程序 4 天但没有成功后,我正在写这个问题...

关于项目:
JDK:阿祖尔 JavaFX 8.42.0.23
构建工具:Maven
Ide:Intelij
ProGuard 版本:6.2.2

问题是什么:
我无法正确混淆我的代码。在将应用程序构建为本机和 fatjar 之后,一切正常。混淆后我有以下错误:

 javafx.fxml.LoadException: 
file:/C:/Users/pawel/Desktop/X/X/target/X-1.3-jar-with-dependenciesOBF.jar!/fxml/MainWindow.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2848)
    at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2692)
    at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2661)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at c.b.g(SourceFile:227)
    at c.b.i(SourceFile:36)
    at c.b.a(SourceFile:194)
    at c.b.a(SourceFile:183)
    at com.d.a.a.a(SourceFile:32)
    at com.sun.javafx.application.PlatformImpl.lambda$null(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException
    at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2899)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2846)
    ... 17 more

当前的 progard 设置:

-injars 'C:\Users\pawel\Desktop\PROJEKTY JAVA\x\target\jfx\native\x\app\x-1.3-jfx.jar'
-outjars 'C:\Users\pawel\Desktop\PROJEKTY JAVA\x\target\jfx\native\x\app\x-1.3-jfxOBF.jar'
-injars 'C:\Users\pawel\Desktop\PROJEKTY JAVA\x\target\x-1.3-jar-with-dependencies.jar'
-outjars 'C:\Users\pawel\Desktop\PROJEKTY JAVA\x\target\x-1.3-jar-with-dependenciesOBF.jar'

-libraryjars 'C:\Program Files\Java\jre1.8.0_181\lib\rt.jar'
-libraryjars 'C:\Program Files\Java\jre1.8.0_181\lib\javaws.jar'
-libraryjars 'C:\Program Files\Java\jre1.8.0_181\lib\ext\jfxrt.jar'

-verbose
-dontnote
-dontwarn
-dontoptimize
-dontshrink

# Keep names of fields marked with @FXML, @Inject and @PostConstruct attributes
-keepclassmembers class * {
  @javafx.fxml.FXML *;
  @javax.inject.Inject *;
  @javax.annotation.PostConstruct *;
}

# Keep entry-point class
-keep class main.Main {
  public static void main(java.lang.String[]);
}

# Keep all annotations and meta-data
-keepattributes *Annotation*,Signature,EnclosingMethod

# Save meta-data for stack traces
-printmapping out.map
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# Rename FXML files together with related views
-adaptresourcefilenames **.fxml,**.png,**.css,**.properties
-adaptresourcefilecontents **.fxml
-adaptclassstrings

此外,我还查看了来自 Whosebug 的建议:
将所有 FXML 文件的名称更新为大写
添加所有类名列表作为 classobfuscationdictionary

其他信息,我有应用程序的预加载器(带有徽标和加载栏的单个 fxml)并且它正在运行。问题是当我尝试加载 main window 的应用程序时,其中 fxml 包含包含标签。

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXProgressBar?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="2000.0" prefWidth="2000.0" style="-fx-background-color: #323234;" styleClass="main-container" stylesheets="@../css/mainStyles.css" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.MainScreenController">
   <children>
      <VBox layoutX="300.0" layoutY="31.0" prefHeight="358.0" prefWidth="289.0">
         <children>
            <HBox alignment="CENTER" spacing="20.0" VBox.vgrow="ALWAYS">
               <padding>
                  <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
               </padding>
               <VBox.margin>
                  <Insets />
               </VBox.margin>
            </HBox>
            <HBox prefHeight="100.0" prefWidth="200.0" />
            <HBox prefHeight="100.0" prefWidth="200.0" />
         </children>
      </VBox>
   </children>
   <left>
      <fx:include source="menus/MenuLeft.fxml" BorderPane.alignment="TOP_LEFT" />
   </left>
   <top>
      <fx:include source="menus/MenuTop.fxml" />
   </top>
   <bottom>
      <JFXProgressBar fx:id="progressBar" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="3.0" BorderPane.alignment="CENTER" />
   </bottom>
   <center>
      <ScrollPane fitToHeight="true" fitToWidth="true" BorderPane.alignment="TOP_LEFT">
         <content>
            <VBox fx:id="vContainer" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" />
         </content>
      </ScrollPane>
   </center>
</BorderPane>

经过 5 天的寻找,我找到了解决方案。

问题是由从 javax 包外部导入 fxml 文件引起的。要解决此问题,我们必须:

选中下面的复选框:

并将导入添加为 "keep"

带有方法和字段以及两颗星**: