AdMob’s Unfriendly JAR on Android

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:

import A;
import B;
import C
etc

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:

-repackageclasses ‘custom.package.here’

This will change your classes to custom.package.here.A, custom.package.here.B, etc. Now they’ll no longer conflict!

 

Free Android “Back to School” Webinars

Back to School Android Webinars – Aug 29 – Sept 9

Yup – we know what it will be like in a few weeks. September is right around the corner and your brain will be like mush from an overload of Netflix, the summer heat, and probably too much fresh air. Not to fear – the Back to School Webinar series is coming your way August 29 to September 9. Get ahead on your Android ABCs and find out the secrets to making great apps.  Hosted by WIP and Sponsored by Immersion, the leader in haptic technology. 

 

Don’t forget to register for the Crittercism session on Wednesday, August 31  9am PDT .  Signup  and get your seat now!  http://www.wipconnector.com/wipjam/entry/back_to_school_webinars

 

Follow

Get every new post delivered to your Inbox.