1

I am trying to enable proguard in my application, which uses my other project as library, Library project has many 3rd party libs like spring,

while generating signed apk with proguard it gives me reference not found from R$id of library project,

i can not exclude library project from obfuscating...

Help me.. Stuck with this from 1 week...

Anirudh
  • 13
  • 3

2 Answers2

0

Most projects will include a list of ProGuard rules they need added in order to function correctly.

If they don't you will need to play some hit and miss until you get a good compile (and decent size reduction).

Are you using this default ruleset?

proguardFiles getDefaultProguardFile("proguard-android-optimize.txt")

That contains a set of rules that will cover all basic requirements for an Android App. You can then add your own rules in an additional config file:

proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard.cfg"

If you are getting errors related to R then you are probably not running a correct base config.

For example, in proguard-android-optimize.txt it ensures that R is correctly maintained:

-keepclassmembers class **.R$* {
    public static <fields>;
}
Knossos
  • 15,802
  • 10
  • 54
  • 91
  • do i have to add rules in library project, or just in my main application? – Anirudh Jun 23 '16 at 09:00
  • It works either way. It is good to put library specific rules in the library project. However, you can lump them all in your main project if you so desire. – Knossos Jun 23 '16 at 09:03
  • when i added R related config in proguard-android-optimize.txt it solved my reference not found from R$id issue, – Anirudh Jun 23 '16 at 09:44
  • Now i am getting issue related to Warning:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter: can't find superclass or interface java.beans.PropertyEditorSupport – Anirudh Jun 23 '16 at 09:44
  • There will likely be a very long list of things you need to keep. I will not guide you through all of them. Long story short, you need to read up on ProGuard if you are going to turn it on. You will specifically want to read up on `-keep xxx` and `-dontwarn xxx`. In this latest case, it might be enough to keep that class `-keep class java.beans.PropertyEditorSupport`. – Knossos Jun 23 '16 at 09:49
0

You should add rules for all libraries you use. This is article for Spring.
Some useful information here.
If it's your project you can just keep everything from it

-keep class com.example.project.** { *; }
-dontwarn class com.example.project.**
Community
  • 1
  • 1
thealeksandr
  • 1,686
  • 12
  • 17