Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using getResource with ProGuard results in null result

Tags:

java

proguard

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
like image 593
Gregory Peck Avatar asked Jun 14 '13 15:06

Gregory Peck


1 Answers

ProGuard expects dots in packages names, and slashes in file names and directory names:

-keeppackagenames com.example.mypackage
-keepdirectories  com/example/mypackage
like image 134
Eric Lafortune Avatar answered Sep 28 '22 05:09

Eric Lafortune