7

Using ProGuard on my jar files has broken my calls to class.getResource(""). I have seen that in the ProGuard manual you need to specify the -keepdirectories mypackage (manual link). However, I have specified the -keepdirectories option and it doesn't seem to be working. I think there is something wrong with my ProGuard configuration. I have also looked at this related question, but I am having trouble getting the -keeppackagenames working as well.

In my code I have something similar to the following.

package com.example.mypackage;
public class MyClass{
    public static void main(String [] args){
        //url is always returned as null
        URL url = MyClass.class.getResource("");
        //do additional stuff including retrieving manifest file
    }
}

ProGuard Configuration

-injars ...
-outjars ...
-libraryjars ...

-dontoptimize
-keepattributes SourceFile,LineNumber,Table,LocalVariable*Table,*Annotation*
-renamesourcefileattribute SourceFile

-repackageclasses
-overloadaggressively

-keep public class com.example.mypackage.MyClass{
    public static void main(java.lang.String[]);
}
-keepdirectories com.example.mypackage,com.example.mypackage.MyClass
-keeppackagenames com.example.mypackage,com.example.mypackage.MyClass
4

2 回答 2

6

ProGuard 需要在包名中使用点,在文件名和目录名中使用斜杠:

-keeppackagenames com.example.mypackage
-keepdirectories  com/example/mypackage
于 2013-06-20T00:55:17.787 回答
0

我发现我能够通过以下修改使其工作-keepdirectories

-keepdirectories **mypackage**

然而,这感觉有点笨拙,虽然它有效,但我觉得好像有更好的解决方案。

于 2013-06-14T20:46:07.830 回答