java proguard 使用_使用proguard混淆java9代码

本文主要研究一下如何使用proguard混淆java9代码

maven

com.github.wvengen

proguard-maven-plugin

package

proguard

6.0.1

${project.build.finalName}.jar

${project.build.finalName}.jar

!META-INF/maven/**,!module-info.class

true

${project.basedir}/proguard.cfg

${java.home}/jmods/java.base.jmod(!**.jar;!module-info.class)

net.sf.proguard

proguard-base

6.0.1

runtime

这里使用6.0.1版本的proguard-base

proguard.cfg

-target 9

-dontshrink

-dontoptimize

-useuniqueclassmembernames

-adaptclassstrings

-dontusemixedcaseclassnames

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-keepclasseswithmembers public class * { public static void main(java.lang.String[]);}

这里target要指定为9版本

问题

duplicate class definitions

[proguard] Warning: class [META-INF/versions/9/org/apache/logging/log4j/util/ProcessIdUtil.class] unexpectedly contains class [org.apache.logging.log4j.util.ProcessIdUtil]

[proguard] Reading library jar [/Users/demo/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.10.0/log4j-to-slf4j-2.10.0.jar]

[proguard] Reading library jar [/Users/demo/.m2/repository/org/apache/logging/log4j/log4j-api/2.10.0/log4j-api-2.10.0.jar]

[proguard] Note: duplicate definition of library class [org.apache.logging.log4j.util.ProcessIdUtil]

[proguard] Note: duplicate definition of library class [org.apache.logging.log4j.util.StackLocator]

[proguard] Reading library jar [/Users/demo/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar]

[proguard] Reading library jar [/Users/demo/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar]

[proguard] Warning: class [META-INF/versions/9/org/apache/logging/log4j/util/StackLocator.class] unexpectedly contains class [org.apache.logging.log4j.util.StackLocator]

[proguard] Note: there were 2 duplicate class definitions.

[proguard] (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)

[proguard] Warning: there were 2 classes in incorrectly named files.

[proguard] You should make sure all file names correspond to their class names.

[proguard] The directory hierarchies must correspond to the package hierarchies.

[proguard] (http://proguard.sourceforge.net/manual/troubleshooting.html#unexpectedclass)

[proguard] If you don't mind the mentioned classes not being written out,

[proguard] you could try your luck using the '-ignorewarnings' option.

[proguard] Error: Please correct the above warnings first.

如果没有使用到log4j的话,可以在progurard.cfg文件中配置dontwarn忽略

can't find referenced class

[proguard] Warning: cn.example.Demo: can't find referenced class java.io.ByteArrayOutputStream

[proguard] Warning: there were 858 unresolved references to classes or interfaces.

[proguard] You may need to add missing library jars or update their versions.

[proguard] If your code works fine without the missing classes, you can suppress

[proguard] the warnings with '-dontwarn' options.

[proguard] (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)

[proguard] Warning: there were 1 unresolved references to library class members.

[proguard] You probably need to update the library versions.

[proguard] (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)

[proguard] Error: Please correct the above warnings first.

这种多半是没有配置好libraryjars的问题,比如这里就是没有配置java.base.jmod的问题。如果还依赖有其他jmod,可以根据具体日志修改配置。

Can't read java.base.jmod

[proguard] Reading library directory [/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/jmods/java.base.jmod(!**.jar;!module-info.class)]

[proguard] Error: Can't read [/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/jmods/java.base.jmod(!**.jar;!module-info.class)] (No such file or directory: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/jmods/java.base.jmod(!**.jar;!module-info.class))

这个是在maven的pom文件配置lib引起的

${java.home}/jmods/java.base.jmod(!**.jar;!module-info.class)

可能是该plugin的问题,将其配置移到proguard.cfg就可以

-libraryjars /jmods/java.base.jmod(!.jar;!module-info.class)

小结

这里的例子仅仅还是jdk是模块化的,但是工程代码还没有模块化。等所有依赖都模块化了,可以重新试验一下。

doc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值