3

我整天都在尝试混淆我们正在开发的 Web 应用程序(我们将允许大客户将其托管在他们的服务器上),并且在浏览、搜索和尝试了很多之后,我无法减少收到的错误数量: “有 7283 个未解析的类或接口引用”

我从 20K 开始,所以我设法得到了一些改进......

这是我正在使用的 pom 配置:

<plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.proguard</groupId>
                        <artifactId>proguard-base</artifactId>
                        <version>4.8</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>             
                <configuration>
                    <obfuscate>true</obfuscate>
                    <includeDependency>true</includeDependency>
                    <options>
                        <option>-target 1.6</option>                    
                        <option>-allowaccessmodification</option>
                        <option><![CDATA[
                            -keep public class * {
                                public <init>(...);  
                                public void set*(...); 
                                public void init*(...); 
                                public void close*(...); 
                                public ** get*(...); 
                                public boolean is*(...); 
                                public boolean can*(...); 
                            } 
                            ]]></option>
                        <option><![CDATA[
                            -keepclassmembers class * { 
                                @javax.inject.Inject *; 
                                @javax.inject.Named *; 
                                @org.springframework.beans.factory.annotation.Autowired *; 
                                @org.springframework.beans.factory.annotation.Qualifier *; 
                                @org.springframework.beans.factory.annotation.Value *; 
                                @org.springframework.beans.factory.annotation.Required *;
                            }
                            ]]></option>                            
                        <option>-keep @org.springframework.stereotype.Service class *</option>
                        <option>-keep @org.springframework.stereotype.Controller class * </option>
                        <option>-keep @org.springframework.stereotype.Component class * </option>
                        <option>-keep @org.springframework.stereotype.Repository class *</option>
                    </options>
                    <inFilter>com/proton/**,!com/proton/protocol/**</inFilter>
                    <injar>${build.warname}.${project.packaging}</injar>
                    <outjar>${build.warname}-proguarded.${project.packaging}</outjar>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                    <addMavenDescriptor>false</addMavenDescriptor>
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                        <lib>${java.home}/lib/jce.jar</lib>                      
                        <lib>${java.home}/lib/jsse.jar</lib>
                    </libs>
                    <proguardVersion>4.8</proguardVersion>
                </configuration>
            </plugin>

结果日志的很大一部分: https ://raw.github.com/gist/3708235/37b4cada40fa4742fd1e3ef0f24efd69fa232b28/Proguard

似乎至少有很大一部分错误来自 Spring 库,我确信我必须大量使用 keep 规则来修复一些动态调用,但如果有人可以帮助解决所有这些错误,我会很棒。

4

2 回答 2

4

我忘了我有这个问题,这是我们现在使用的设置:

<plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>4.8</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>             
            <configuration>
                <obfuscate>true</obfuscate>
                <includeDependency>true</includeDependency>
                <options>
                    <option>-target 1.6</option>                    
                    <option>-dontoptimize</option>
                    <option>-keepdirectories</option>
                    <option>-renamesourcefileattribute SourceFile</option>
                    <option>-keepparameternames</option>
                    <option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option>
                    <option><![CDATA[
                        -keep public class com.proton.commons.** { public protected *; }
                        ]]></option>    
                            <!-- Here comes a lot of interface packages, public classes, etc as the last one -->    
                    <option><![CDATA[
                        -keepclassmembers enum * {
                            public static **[] values();
                            public static ** valueOf(java.lang.String);
                        }                       
                        ]]></option>        
                    <option><![CDATA[
                        -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 *;
                            @javax.annotation.PostConstruct *;
                            @javax.annotation.PreDestroy *;
                            @org.aspectj.lang.annotation.AfterReturning *;
                            @org.aspectj.lang.annotation.Pointcut *;
                            @org.aspectj.lang.annotation.AfterThrowing *;
                            @org.aspectj.lang.annotation.Around *;
                        }
                        ]]></option>                            
                    <option>-keep @org.springframework.stereotype.Service class *</option>
                    <option>-keep @org.springframework.stereotype.Controller class * </option>
                    <option>-keep @org.springframework.stereotype.Component class * </option>
                    <option>-keep @org.springframework.stereotype.Repository class *</option>
                    <option>-keep @org.springframework.cache.annotation.EnableCaching class *</option>
                    <option>-keep @org.springframework.context.annotation.Configuration class *</option>
                 <!-- Custom annotation -->
                    <option>-keep @com.proton.ks.aop.ProtonLogging class *</option>
                    <option>-keep @org.aspectj.lang.annotation.Aspect class *</option>
                    <option>-keep @java.lang.annotation.Retention class *</option>
                    <option>-keep @java.lang.annotation.Target class *</option>
                    <option>-dontwarn javax.**</option>
                    <option>-dontnote com.proton.ks.preferences.PreferenceFactory</option>
                </options>
                <addMavenDescriptor>false</addMavenDescriptor>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                    <lib>${java.home}/lib/jce.jar</lib>                      
                    <lib>${java.home}/lib/jsse.jar</lib>
                    <lib>${java.home}/lib/ext/sunjce_provider.jar</lib>
                </libs>
                <proguardVersion>4.8</proguardVersion>
            </configuration>
        </plugin>
于 2013-07-04T15:06:48.730 回答
1

我已经使用 -dontskipnonpubliclibraryclasses 解决了很多问题。

于 2012-11-12T19:00:09.340 回答