以前试过在Ant下使用Proguard,感觉挺简单的,使用Maven后,明显复杂多了,复杂不在Proguard,而在proguard-maven-plugin。
配置如下:
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<proguardInclude>${basedir}/proguard.pro</proguardInclude>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
</plugin>
出现异常:
[proguard] Obfuscating
[proguard] Printing mapping to [D:\cces\linker\target\proguard_map.txt]
[proguard] Preverifying
[proguard] Unexpected error while performing partial evaluation:
[proguard] Class = [net/sicross/tms/service/cces/SearchFlightOrderDetailService]
[proguard] Method = [getRouteDetail(Ljava/util/Map;)Ljava/util/List;]
[proguard] Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [java/util/List] and [java/lang/StringBuffer])
[proguard] Unexpected error while preverifying:
[proguard] Class = [net/sicross/tms/service/cces/SearchFlightOrderDetailService] [proguard] Method = [getRouteDetail(Ljava/util/Map;)Ljava/util/List;]
[proguard] Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [java/util/List] and [java/lang/StringBuffer])
[proguard] java.lang.IllegalArgumentException: Can't find common super class of [java/util/List] and [java/lang/StringBuffer]
[proguard] at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:330)
[proguard] at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:467)
[proguard] at proguard.evaluation.Variables.generalize(Variables.java:137)
[proguard] at proguard.evaluation.TracedVariables.generalize(TracedVariables.java:140)
[proguard] at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:637)
根据异常,先是怀疑有什么jre的包没有导入,增加了另外几个也不行。在怀疑是jdk编译版本的问题,因为输出目标jdk版本是1.6的,在proguard-maven-plugin的configuration中增加下面的配置也没有。
<options>
<option>-target 1.6</option>
</options>
最后,将maven的target=1.6改为1.5后,异常消失。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.0.2</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Powered by ScribeFire.