- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力解决 JavaFX 应用程序的混淆问题。使用此项目作为基础:
https://github.com/openjfx/samples/tree/master/IDE/IntelliJ/Non-Modular/Gradle
Proguard 抛出此错误:
java.io.IOException: Can't write [Path\infile.jar] (Can't read [Path\outfile.jar] (Duplicate jar entry [a.class]))
混淆器配置文件: -不优化 -不要缩小
-libraryjars 'E:\Prog\jdk-11.0.2\jmods'
-libraryjars 'E:\Prog\javafx-sdk\lib'
# Save meta-data for stack traces
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
# Rename FXML files together with related views
-adaptresourcefilenames **.fxml,**.png,**.css
-adaptresourcefilecontents **.fxml
-adaptclassstrings
# Keep all annotations and meta-data
-keepattributes *Annotation*,Signature,EnclosingMethod
# Keep entry-point class
-keep classpackage.App {
public static void main(java.lang.String[]);
}
# Keep all classes inside application
-keep,allowobfuscation class package.** {
}
# Keep names of fields marked with @FXML attribute
-keepclassmembers class * {
@javafx.fxml.FXML *;
}
有人有 JavaFX 混淆的经验吗?
最佳答案
要让 Proguard 与 Java 11 配合使用,我们需要:
最新的 Proguard beta version ,在本例中适用于 Gradle。
修改构建 gradle 文件以包含 proguard 任务。
添加 proguard 配置文件,其中包括 Java 11 所需的更改。
构建.gradle
从 HelloFX sample 开始,构建将修改为:
// 1. Include proguard dependency
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2'
}
}
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
repositories {
mavenCentral()
}
dependencies {
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
mainClassName = 'org.openjfx.MainApp'
我将添加更多任务来用混淆器替换默认的构建/类,而不是仅仅添加混淆器任务。这有助于检查结果。
// 2. Add tasks
// 2.1 Clean buildDir before running proguard
task cleanClasses(type: Delete) {
delete "${buildDir}/classes/java/main"
delete "${buildDir}/resources/java/main"
}
classes.dependsOn(cleanClasses)
// 2.2 Add proguard task
task proguard(type: proguard.gradle.ProGuardTask, dependsOn: classes) {
injars project.sourceSets.main.output
outjars "${buildDir}/proguard/output.jar"
libraryjars project.sourceSets.main.compileClasspath
configuration 'proguard.conf'
}
// 2.3 Clean after proguard task
task cleanAfterProguard(type: Delete, dependsOn: proguard) {
delete "${buildDir}/classes/java/main"
delete "${buildDir}/resources/java/main"
}
// 2.4 Extract output jar to buildDir
task unpackProguardOutput (type: Copy, dependsOn: cleanAfterProguard) {
from zipTree("${buildDir}/proguard/output.jar")
into file("${buildDir}/classes/java/main")
}
最后,添加一个任务来运行带有混淆类的应用程序。
// 3. Create a task to run the app with the proguarded buildDir
task runProguard(type: JavaExec, dependsOn: unpackProguardOutput) {
classpath = sourceSets.main.runtimeClasspath
jvmArgs = ['--module-path', classpath.asPath,
'--add-modules', 'javafx.controls,javafx.fxml' ]
main = 'a.a.b' // <-- this name will depend on the proguard result
}
proguard.conf
如何让它与 Java 9+ 一起工作的关键可以在这个 comment 中找到。如果您下载源代码,并检查示例文件夹,会发现有不同的配置文件。
检查applications.pro
,您可以阅读:
# Before Java 9, the runtime classes were packaged in a single jar file.
#-libraryjars <java.home>/lib/rt.jar
# As of Java 9, the runtime classes are packaged in modular jmod files.
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
就是这样!
这是我在 HelloFX 示例中使用的配置文件(当然可以使用其他许多选项进行扩展):
-dontoptimize
-dontshrink
#Java 9+
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
# 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
# Keep all annotations and meta-data
-keepattributes *Annotation*,Signature,EnclosingMethod
# Keep entry-point class
-keep class org.openfjx.MainApp {
public static void main(java.lang.String[]);
}
# Keep names of fields marked with @FXML, @Inject and @PostConstruct attributes
-keepclassmembers class * {
@javafx.fxml.FXML *;
@javax.inject.Inject *;
@javax.annotation.PostConstruct *;
}
结果
如果运行./gradlew proguard
,您将获得output.jar
。
如果运行./gradlew unpackProguardOutput
,您可以在build/classes
中看到结果:
main
|____a
| |____a
| | |____styles.css
| | |____scene.fxml
| | |____b.class
| | |____a.class
在本例中,b.class
是主类,因此这就是为什么在 runProguard
任务中我设置了 main = 'a.a.b'
。显然,这取决于具体情况。
此外,您可以查看out.map:
org.openjfx.FXMLController -> a.a.a:
javafx.scene.control.Label label -> label
10:10:void <init>() -> <init>
17:20:void initialize(java.net.URL,java.util.ResourceBundle) -> initialize
org.openjfx.MainApp -> a.a.b:
11:11:void <init>() -> <init>
15:23:void start(javafx.stage.Stage) -> start
26:27:void main(java.lang.String[]) -> a
最后,./gradlew runProguard
将成功运行应用程序。
关于JavaFX Proguard 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54892406/
https://www.guardsquare.com/en/proguard/manual/optimizations说 class/unboxing/enum Simplifies enum ty
我想使用 ProGuard 重命名变量和函数。我希望生成的类文件在所有方面都与源 jar 相同,除了名称。有没有办法做到这一点? 我尝试使用 dontoptimize 和 dontshrink 无效。
例如,这条规则在 proguard 中意味着什么: -keep class myjava.** {*;} 我理解 {*;} 部分意味着类中的所有成员和方法。但是包名中的 2 个星号是什么意思? 提前致
我有一个即将使用 ProGuard 混淆的库。 “图书馆模式”几乎适用于我的用例,即保留所有公共(public)和 protected 类和类成员几乎没问题。 然而,由于 Java 的可见性要求,一些
在我的 Playstore 中,我注意到去混淆后的代码包含相当多的 在堆栈跟踪中。 (例如 at .onAttach(ProfileLandingFragment.java) )。 有什么用真正意思?
我收到了一封来自 Google 的关于 unsafe implementation of TrustManager 的电子邮件唯一的线索是有问题的代码在 com.b.a.af 类中。显然,这是混淆的名
我读自 http://proguard.sourceforge.net/manual/usage.html关于assumenosideeffects的使用。我的问题涉及以下段落: -assumenos
什么是智能 ProGuard 配置来混淆特定类 com.acme.Algorithm 的私有(private)方法和常量? 我想对此进行混淆,因为它包含一个算法,当意外打开 .jar 时,该算法不应该
最近将 Pushwoosh 库集成到我的 Android 应用程序中。它运作良好。但是在导出为签名应用程序时遇到以下错误。请帮忙。提前致谢。 Proguard returned with error
有没有人有使用ProGuard的经验是否已经有超出类加载时间的应用程序性能测量? 我有一个相当复杂的应用程序,可能需要改进,但为 ProGuard 准备它需要几天时间,所以我想先听听一些意见。 最佳答
当我尝试使用 android studio 3.2 canary 17 构建应用程序包时,我收到以下错误消息。我不知道我所有的 proguard 文件中缺少什么角括号,一切似乎都很好,并且在旧版本的
我遇到了 proguard 的问题,我刚刚配置了 Bugsense 并且使用了它们的配置建议,我在 google 和 stackoverflow 上进行了搜索,通常 ppl 可以在控制台中看到该行或问
我第一次尝试使用 Proguard,我收到此错误,有人可以帮我吗?谢谢 [2014-09-03 11:44:58 - P - Photos] Proguard returned with error
当我收到此错误时,我正在尝试导出启用了 proguard 的 android 应用程序:- Proguard returned with error code 1. See console pro
看起来有两个用于运行 ProGuard 的 SBT 插件。任何人都可以谈谈他们的相对优势和劣势吗?我还没有在网上找到比较。 xsbt-proguard-plugin - https://github.
Proguard 会条纹 kotlin.Unit 独立对象(在 Kotlin 运行时库中),如果您使用此类型,则会导致编译错误。以下规则无助于保留此元素(可能是因为 Unit 不是一个类,它是一个对象
构建 Android 发行版 apk 时,Smack 4.1 的正确 ProGuard 规则是什么? 目前,我正在使用 aSmack github 存储库上 README.asmack 文件中的 aS
尝试使用 Proguard Maven 插件时出现 OutOfMemoryErrors。我尝试通过将 MAVEN_OPTS 环境变量设置为 -Xmx2g 来为 Maven 分配更多内存,但这没有任何区
我有一个 pom.xml 文件如下。当我运行 mvn clean install 时,出现错误 [proguard] Error: Can't read [C:\Program Files\Java\
我已经将支持库从 v22.2.1 更新到 v23.0.0,在构建应用程序后(使用 minifyEnabled true)我有“AppCompat 不支持当前主题功能”异常: 08-23 05:46:1
我是一名优秀的程序员,十分优秀!