Obfuscating method with throws clause

2019-03-17 22:02发布

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.

2条回答
男人必须洒脱
2楼-- · 2019-03-17 22:21

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>
查看更多
祖国的老花朵
3楼-- · 2019-03-17 22:34

I figured it out.

-keepattributes Exceptions

查看更多
登录 后发表回答