Android Ideas
26May/110

App Developers: Be careful with Proguard and Eclipse “User Libraries”

One convenient feature of the Eclipse IDE is that it lets you create "user libraries" to hold jars as well as source, javadocs, etc. This is useful even if you only have one jar in there, since you can update that jar and all the projects that use it instantly use the new jar.

While this is convenient, I've spent way too long fighting with Proguard while it says things like

can't find referenced class com.google.ads.AdView

and suggests

You may need to specify additional library jars (using '-libraryjars'), or perhaps the '-dontskipnonpubliclibraryclasses' option.

when I know good and well the jars are there.

Upon Googling the problem I found many solutions that involve using "-keep public class" and "-libraryjars" along with other such things. The right combination of these allow Proguard to complete and produce the APK, but your app will ultimately fail upon run:

Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader

Well, if you're having this problem give this a try:

The Solution

Do you have any "user libraries" in your project? Well get rid of those and replace them with the actual jars, then be amazed that such a silly thing could have been your problem all along. Of course this isn't optimal since if you're using user libraries you probably want them in there. There might be a way to keep them and still use Proguard, but I'm not sure. Either way, I hope I've saved you some time. Happy coding!