130

So, I'm TRYING to release some software but Proguard is giving me a headache.

When I try to export using proguard I'm getting lots of warning ie "can't find referenced class"

For example:

[2011-08-07 17:44:37 - GAME] Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
[2011-08-07 17:44:37 - GAME] Warning: there were 52 unresolved references to classes or interfaces.
[2011-08-07 17:44:37 - GAME]          You may need to specify additional library jars (using '-libraryjars'),
[2011-08-07 17:44:37 - GAME]          or perhaps the '-dontskipnonpubliclibraryclasses' option.
[2011-08-07 17:44:37 - GAME] java.io.IOException: Please correct the above warnings first.
[ 

The warnings seem to related to simpleframework, so in my proguard config file I've added the following:

-libraryjars pathtoprojecttolibs\simple-xml-2.4.jar

Where pathtoprojecttolibs is the path to jars which are referenced by my project.

This makes NO difference.

If simpleframework references javax can I tell proguard to ignore this too??

Any ideas?

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
iasksillyquestions
  • 5,558
  • 12
  • 53
  • 75
  • 1
    Are you using proguard just to do treeshaking? If so, have you checked you file size without using it? You can get superwierd bugs when proguard throws out something that is accessed using reflection for instance which you won't find until it breaks runtime so be really, really sure you need it. – alun Aug 07 '11 at 17:25
  • I was really only using it to try to protect the code being nicked as easily? Do you think its worth it? – iasksillyquestions Aug 07 '11 at 17:27
  • 3
    @ListenToRick Proguard is perfectly fine, if it's run with the proper configs and your resultant app tested properly. I'm pretty sure Google even recommends its use. Google provides a lot of guides/examples for using Proguard with Android apps. – CrackerJack9 Aug 07 '11 at 17:44
  • Proguard is a good tool but google recommending it is probably at least as much because of a rather wierd size limitation in the dex-format as anything else. (See http://code.google.com/p/android/issues/detail?id=7147) – alun Aug 07 '11 at 17:54
  • 5
    @alun, that's not the reason. Those of us who don't want our apps reverse engineered, or who are using licensing to 'try' to prevent piracy should use an obfuscation tool such as this to make it harder for would be hackers. Making your application take less space is also a benefit for the end user, and there are also optimizations made by these tools as well... yet another benefit. – Christopher Perry Oct 23 '11 at 04:28

9 Answers9

128

org.simpleframework.xml.stream.StreamReader in your code refers to javax.xml.stream.events.XMLEvent. The latter class is part of the Java runtime (rt.jar) but not part of the Android runtime (android.jar), so ProGuard warns that something might be broken. If you're sure that your application works anyway, you can specify

-dontwarn javax.xml.stream.events.**

ProGuard hell?

Wesley
  • 4,084
  • 6
  • 37
  • 60
Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • 15
    That did not fix it for me, however this did `-dontwarn javax.xml.**` – Jeshurun May 27 '12 at 14:50
  • 8
    Adding `-libraryjars /lib/rt.jar` fixed the issue for me. – Gautam Dec 27 '12 at 07:40
  • For those running into similar warnings with **Guava**, [check out this answer](http://stackoverflow.com/questions/9120338/proguard-configuration-for-guava-with-obfuscation-and-optimization/20935044#20935044). – Jonik Jan 05 '14 at 15:10
  • 3
    I got additional warnings about eg javax.xml.stream.XMLInputFactory, so i used `-dontwarn javax.xml.stream.**` – spatialist Jan 16 '14 at 11:08
  • 1
    How can I set `-dontwarn` sing the GUI? – Tomáš Zato May 09 '15 at 19:04
  • 1
    Its weird I still encountered this problem in 2018, I am not sure what I missed but is this solution still apply in 2018 without some drawbacks? – Neon Warge Apr 23 '18 at 03:34
9

In my case the root cause was here. Those warnings you can just skip with :

-dontwarn org.simpleframework.xml.stream.**

The original answer is here

Community
  • 1
  • 1
6

This error occurs because the libs you use depend on other libs which are not realy used, but Proguard is looking for them.
Add your -dontwarn lines to your proguard-rules.pro file in your Android project to disable this warnings.

enter image description here

You can find which dependencies you need to add to your proguard-rules.pro in the stacktrace of your error.

Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
3

My Magic key that solved my hours of searching: Add this to progruard-android.txt

-dontskipnonpubliclibraryclassmembers
Ashraf Alshahawy
  • 1,139
  • 1
  • 14
  • 38
3

You should include this in your Proguard config:

-dontskipnonpubliclibraryclasses
CrackerJack9
  • 3,650
  • 1
  • 27
  • 48
  • Well, it did for me at the time...~4 years ago...things may have changed since then :) Seemed to have worked for at least 2 other people anyway. – CrackerJack9 Jun 08 '15 at 18:01
  • The default [proguard-android.txt](https://android.googlesource.com/platform/sdk/+/android-4.1.2_r2/files/proguard-android.txt) already has this line. – CristinaTheDev Jul 07 '17 at 12:52
  • 1
    @Ultimecia that commit is from 2013, this post was made in 2011 – CrackerJack9 Jul 07 '17 at 18:40
0

I think this is an edge case but in my case I had to completely wipe the build folder on my Jenkins proguard tried to work with old code which was not there any more - just in case anybody has the same issue.

luckyhandler
  • 10,651
  • 3
  • 47
  • 64
0

In my case I haven't changed anything and warning started to show. The problem was with broken gradle caches. Check my other answer. I share with this because it took my 2 hours to find the problem :]

AppiDevo
  • 3,195
  • 3
  • 33
  • 51
0

Add this line to your proguard-rules.pro file in the gradle scripts directory:

-dontwarn package.class.name.**

where package.class.name is the package name with the class name of the jar file appended.

For example:

-dontwarn com.myexternalclass.utils.**
0

Hmm. Reading that warning it would seem the library you are trying to use has a dependancy on javax.xml.stream.events. I don't think that namespace is actually included in android at all. (See Package Index).

Try deploying it to the emulator without using proguard and see if it works. My guess would be no if that warning is accurate.

alun
  • 3,393
  • 21
  • 26
  • Hi, if it is working in emulator without the proguard, it means the warnings are inaccurate? I am trying to figure out why I had these kind of similar warnings. I don't want to just suppress the warnings. – Michelle Shieh Aug 18 '17 at 09:09