Obfuscating method with throws clause

不打扰是莪最后的温柔 提交于 2019-12-03 15:20:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!