18

I'm have added external jar file to the libs folder of mt project and configure it in the build path. When i try to "Export Android Package" i receive a Proguard error message for a lot of reference classes that aren't found, For example: Warning: com.itextpdf.text.BaseColor: can't find referenced class java.awt.Color

When i tried to debug the BaseColor class worked fine, so i can't figure out why does it warns me.

Any help will be appreciated,

Thanks

Moshik L
  • 410
  • 1
  • 5
  • 14

2 Answers2

46

I tried for days to get external jars properly working. There were suggestions to do things like download the referenced JARS or properly define libjars. None of these worked for me.
What did work was putting this sort of thing in for the JARS that errored:

-dontwarn javax.management.**
-dontwarn java.lang.management.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.slf4j.**
-dontwarn org.json.*

and this:

-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }

(Obviously you will need to adjust this to match your error messages)

Good luck.

Caspar Harmer
  • 8,097
  • 2
  • 42
  • 39
  • This will not harm the functioning of the application? I tried to add '-ignorewarnings' and it works fine, but i am afraid it will cause problems to my application like force close. – Moshik L Jul 29 '11 at 09:01
  • Well, it could remove stuff that you need, but to avoid that, I obfuscated, but didn't compress my code ie, I used these options: -dontshrink -dontoptimize -dontpreverify This means that it obfuscates, but doesn't remove stuff. Also, twitter4j for example seems to include references to libraries that aren't used in my app. – Caspar Harmer Jul 29 '11 at 17:29
  • http://stackoverflow.com/questions/3902943/how-to-includ-additional-javax-packages-in-android-app-with-eclipse – Blundell Aug 09 '11 at 18:01
  • 2
    @Blundell, this issue is not how to add external jars, but how to get Proguard to not complain about them. – Caspar Harmer Aug 09 '11 at 19:10
  • @Casp It won't complain about them if you add them correctly. I came across this issue, found your answer and that Q was the next link I went to. Therefore I posted it to help other's who got here. – Blundell Aug 10 '11 at 07:14
  • Since I'm prepared to give you the benefit of the doubt, I did as the answer said. I got 116 errors. "[2011-08-10 21:23:00 - Consumer_Deals] Warning: there were 116 unresolved references to classes or interfaces." I accept that the reference may address some issues specifically concerning javax, but I think that it is ultimately on of those "lets try everything" solutions. I believe that the above solution is better and more general. – Caspar Harmer Aug 10 '11 at 09:26
  • @Blundell No, the question here is to setup Proguard to not complain about references that are not 'really' needed by the libraries we're using. Proguard is VERY tricky about references, if you disable it Eclipse or Ant has no problem compiling, so these broken references are ONLY a problem for Proguard. THANKS a lot CaspNZ I also spent days on Twitter4j before finally finding this post! – Murphy Oct 17 '11 at 06:18
  • Glad it helped you! I made my first release to the market without Proguard protection in place because of the issue. it's a real show-stopper eh. – Caspar Harmer Oct 17 '11 at 07:28
  • Thanks you very much, now i know how to get rid of those warnings, thanks for the great example, i finally got my app working with proguard(took almost a day of searching on web to get to this solution). – Diljeet Jan 31 '13 at 21:06
  • @CasparHarmer please reply, in android studio where to add these lines, either in 'proguard-project.txt' or 'proguard-rules.pro' ? – Shirish Herwade Jun 06 '16 at 09:15
  • Sorry, no idea. I haven't developed for Android for several years. – Caspar Harmer Jun 06 '16 at 09:44
  • Two asterisks don't compile anymore. Any other solutions? – Daniel Jul 16 '20 at 10:14
0

com.itextpdf.text.BaseColor is included in the jar you have added, I guess. It extends java.awt.Color which is not included in it but in the distribution of Java you are using under Eclipse.

When you are exporting the file, the export process is jammed as java.awt.color doesn't exist in the Android base framework. I don't think this is related to Proguard: this must happen even if you disable the obfuscation.

Shlublu
  • 10,917
  • 4
  • 51
  • 70
  • So do you mean that i have to add the rt.jar ,where the java.awt.color is, to my project for the application to function well? Because i tried to '-ignorewarnings' and it still used this class (BaseColor). – Moshik L Jul 29 '11 at 09:13
  • I don't know whether you can do that actually, as plenty of classes would be in conflict with their Android version. I think you should include the entire AWT source code to have it working. I've never tried but I found this on Anddev, and it seems to confirm: http://www.anddev.org/other-coding-problems-f5/using-java-awt-classes-in-android-t15545.html – Shlublu Jul 29 '11 at 09:17