当我们尝试使用以下配置混淆战争文件时,我们遇到了以下问题。
Note: you're ignoring all warnings!
[proguard] Unexpected error while performing partial evaluation:
[proguard] Class = [autovalue/shaded/com/google$/common/collect/aF]
[proguard] Method = [a(Ljava/util/List;Lautovalue/shaded/com/google$/common/base/i;)Ljava/util/List;]
[proguard] Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [autovalue/shaded/com/google$/common/collect/aF$k] (with 1 known super classes) and [autovalue/shaded/com/google$/common/collect/aF$j] (with 1 known super classes))
[proguard] Unexpected error while preverifying:
[proguard] Class = [autovalue/shaded/com/google$/common/collect/aF]
[proguard] Method = [a(Ljava/util/List;Lautovalue/shaded/com/google$/common/base/i;)Ljava/util/List;]
[proguard] Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [autovalue/shaded/com/google$/common/collect/aF$k] (with 1 known super classes) and [autovalue/shaded/com/google$/common/collect/aF$j] (with 1 known super classes))
[proguard] Error: Can't find common super class of [autovalue/shaded/com/google$/common/collect/aF$k] (with 1 known super classes) and [autovalue/shaded/com/google$/common/collect/aF$j] (with 1 known super classes)
我们的保障设置 pom.xml文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<!-- <configuration>
<finalName>${project.build.finalName}-shaded</finalName>
<outputDirectory>../build</outputDirectory>
</configuration> -->
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<id>proguard</id>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- File with proguard configuration -->
<proguardInclude>${basedir}/build/proguard.conf</proguardInclude>
<obfuscate>true</obfuscate>
<outjar>${project.build.finalName}-proguard.${project.packaging}</outjar>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>${version.net.sf.proguard}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Proguard.conf文件设置
#-include ../build/annotations.pro
-allowaccessmodification
-keeppackagenames
-keepdirectories
-dontshrink
-dontoptimize
-dontwarn
-ignorewarnings
#-applymapping input_mapping.dat
#-printmapping final_mapping.dat
#-dontusemixedcaseclassnames
#-forceprocessing
-keepattributes InnerClasses,SourceFile,LineNumberTable,Deprecated,Signature,Exceptions,*Annotations*,EnclosingMethod
# Keep - Applications. Keep all application classes that have a main method.
-keep public class com.Application {
public static void main(java.lang.String[]);
}
-keep public class com.Application {*;}
-injars ../target/original-Application-0.0.1-SNAPSHOT.war
除了上述conf之外,我还尝试了其他选项,例如..
# autovalue
-dontwarn javax.lang.**
-dontwarn javax.tools.**
-dontwarn javax.annotation.**
-dontwarn autovalue.shaded.com.**
-dontwarn com.google.auto.value.**
-dontwarn javax.servlet.**
-dontwarn sun.misc.**
-dontwarn autovalue.shaded.org.apache.commons.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.log.**
-dontwarn org.apache.velocity.**
-dontwarn org.apache.tools.**
-dontwarn org.jdom.**
-dontwarn org.java.lang.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
# Retrofit
-dontwarn retrofit2.Platform$Java8
-keep class com.google.** { *; }
-keep class org.** { *; }
-keep class javax.** { *; }
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
@retrofit.** *;
}
-keepclassmembers class * {
@retrofit.** *;
}
# Proguard configuration for Jackson 2.x (fasterxml package instead of codehaus package)
-keep class com.fasterxml.jackson.databind.ObjectMapper {
public <methods>;
protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
public ** writeValueAsString(**);
}
-keepattributes *Annotation*,EnclosingMethod,Signature
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-dontwarn com.fasterxml.jackson.databind.PropertyNamingStrategy$LowerCaseWithUnderscoresStrategy
-keep class org.codehaus.** { *; }
-keep class com.fasterxml.jackson.annotation.** { *; }
-keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; }
-keepclassmembers public class com.fasterxml.jackson.databind.PropertyNamingStrategy$LowerCaseWithUnderscoresStrategy {
public <init>(...); }
#Yelp Serializable objects
-keep class com.yelp.clientlib.entities.*$* {
*;
}
-printmapping build/outputs/mapping/release/mapping.txt
-keepnames interface **
-keepparameternames
-keep class !com.slm.proguard.example.spring.boot.domain.** { *; }
-keep interface * extends * { *; }
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Value *;
}
-keep public class * extends org.springframework.boot.web.support.SpringBootServletInitializer
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Qualifier *;
@org.springframework.beans.factory.annotation.Value *;
@org.springframework.beans.factory.annotation.Required *;
@org.springframework.context.annotation.Bean *;
@org.springframework.context.annotation.Primary *;
@org.springframework.boot.context.properties.ConfigurationProperties *;
@org.springframework.boot.context.properties.EnableConfigurationProperties *;
@javax.inject.Inject *;
@javax.annotation.PostConstruct *;
@javax.annotation.PreDestroy *;
}
-keep @org.springframework.stereotype.Service class *
-keep @org.springframework.stereotype.Controller class *
-keep @org.springframework.stereotype.Component class *
-keep @org.springframework.stereotype.Repository class *
-keep @org.springframework.cache.annotation.EnableCaching class *
-keep @org.springframework.context.annotation.Configuration class *
-keep @org.springframework.boot.context.properties.ConfigurationProperties class *
-keep @org.springframework.boot.autoconfigure.SpringBootApplication class *
-allowaccessmodification
-keepclassmembernames class * {
java.lang.Class class$(java.lang.String);
java.lang.Class class$(java.lang.String, boolean);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
public static ** fromValue(java.lang.String);
}
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
!private <fields>;
!private <methods>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired <fields>;
@org.springframework.beans.factory.annotation.Autowired <methods>;
@org.springframework.security.access.prepost.PreAuthorize <methods>;
但是我仍然遇到同样的问题
Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [autovalue/shaded/com/google$/common/collect/aF$k] (with 1 known super classes) and [autovalue/shaded/com/google$/common/collect/aF$j] (with 1 known super classes))
[proguard] Error: Can't find common super class of [autovalue/shaded/com/google$/common/collect/aF$k] (with 1 known super classes) and [autovalue/shaded/com/google$/common/collect/aF$j] (with 1 known super classes)
任何人都可以建议我们必须保留哪个jar作为排除对象或需要保留的类文件。