问题
I'm using ProGuard to obfuscate my code. My project is comprised of a few modules, each obfuscated independently.
One library includes an interface;
public interface IFace {
public int methodA(boolean b) throws CustomException;
}
Another library provides an implmentation
public class IFaceImpl implements IFace {
@Override
public int methodA(boolean b) throws CustomException {
return 0;
}
}
The library with the interface is built first, and the second is built against the obfuscated version. Unfortunately the compile fails on the @Override as the interface does not have the throws clause.
I have proguard keeping the interface and all its members, but I can't figure out how to keep the throws clause.
回答1:
I figured it out.
-keepattributes Exceptions
回答2:
Example with Maven:
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.6</version>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>4.10</proguardVersion>
<options>
<option>-keepattributes Exceptions</option>
<option>-keep public class some.package.SomeClass{*;}</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
</libs>
</configuration>
</plugin>
来源:https://stackoverflow.com/questions/1115515/obfuscating-method-with-throws-clause