One of our team members (thanks Shalin!) recently discovered that our Android library didn’t play well with AdMob. As soon as our library and AdMob’s library were added to the same project, this error showed up:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: …
Conversion to Dalvik format failed with error 1
Here is a stack overflow post that describes other users experiencing similar issues with other jar files. There are many suggested solutions, but none of them worked. After I poked around the AdMob Android library, the real issue became clear — AdMob’s library uses ProGuard to obfuscate its classes, but fails to declare a custom package name. Proguard will change your classes and its imports to look something like:
This means if you add other external libraries that are also guilty of this (like ours!), the classes will have conflicting names and you won’t be build your project. We have since fixed our Android library with one line of (configuration) code, and we invite Google to do the same.
If you are developing a library, and use ProGuard to obfuscate your classes, then
Add this line to your proguard.cfg file:
This will change your classes to custom.package.here.A, custom.package.here.B, etc. Now they’ll no longer conflict!