Using ez-vcard on Android - Clashes with Android's existing Apache commons codec

393 views
Skip to first unread message

web.app...@gmail.com

unread,
Jun 4, 2013, 3:44:20 PM6/4/13
to ez-vcard...@googlegroups.com
Hello all,

I have been trying to get ez-vcard to work on Android but I am running into an unfortunate circumstance.

For the most part ez-vcard was working fine on Android, but with certain vCards, I was getting the following error:
06-04 11:38:08.586: E/AndroidRuntime(1694): java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64
06-04 11:38:08.586: E/AndroidRuntime(1694): at ezvcard.types.BinaryType.parse(BinaryType.java:467)
06-04 11:38:08.586: E/AndroidRuntime(1694): at ezvcard.types.BinaryType.doUnmarshalText(BinaryType.java:331)
06-04 11:38:08.586: E/AndroidRuntime(1694): at ezvcard.types.VCardType.unmarshalText(VCardType.java:279)
06-04 11:38:08.586: E/AndroidRuntime(1694): at ezvcard.io.VCardReader.readNext(VCardReader.java:355)
06-04 11:38:08.586: E/AndroidRuntime(1694): at ezvcard.Ezvcard$ParserChain.first(Ezvcard.java:697)
06-04 11:38:08.586: E/AndroidRuntime(1694): at ezvcard.Ezvcard$ParserChainText.first(Ezvcard.java:752)
06-04 11:38:08.586: E/AndroidRuntime(1694): at ezvcard.Ezvcard$ParserChainTextString.first(Ezvcard.java:834)

Turns out that since Android has Apache Commons Codec 1.2, we are missing some of the functions that ez-vcard needs. See:
http://stackoverflow.com/questions/2047706/apache-commons-codec-with-android-could-not-find-method?rq=1

And it does not seem like we can force Android to use a higher version. Has anyone run into this issue before and what was the solution?

Is there a build of ez-vcard that can work around this issue?

Any help is appreciated!

Michael Angstadt

unread,
Jun 5, 2013, 10:09:19 AM6/5/13
to ez-vcard...@googlegroups.com
It looks like it's failing because the vCard you are parsing has base64-encoded data in it (such as a photo).  ez-vcard uses commons-codec to encode/decode base64 and quoted-printable data.

I wonder if including the class files of commons-codec inside of the ez-vcard JAR will help.  Can you try using the attached JAR and let me know if it works?

Thanks,
Mike
ez-vcard-0.8.2-SNAPSHOT.jar

web.app...@gmail.com

unread,
Jun 5, 2013, 4:30:34 PM6/5/13
to ez-vcard...@googlegroups.com
Hi Mike,

I tried using that new JAR.  The second commons-codec seems to cause a conflict at compile time:

Unable to execute dex: Multiple dex files define Lorg/apache/commons/codec/Decoder;

Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/apache/commons/codec/Decoder;

Sorry, I also should have mentioned in the original post that I was using the ez-vcard JAR without any dependencies in it (I added them all into my project except commons-codec).

One thing I tried doing was renaming the commons codec library (meaning there is the old Android library and the newly renamed one).  I then changed the import statements on the ez-vcard source and it seems to have addressed this issue, but this seems like more of a workaround than an actual solution.

I have given this some thought and searched around the internet for this Android issue and don't think there is a good solution aside from what we see on the Stackoverflow link in the original post.

Let me know if you have any other ideas!

By the way, thank you Mike for developing this library.  I have found it very useful!

Michael Angstadt

unread,
Jun 5, 2013, 5:05:51 PM6/5/13
to ez-vcard...@googlegroups.com
Sorry, I also should have mentioned in the original post that I was using the ez-vcard JAR without any dependencies in it (I added them all into my project except commons-codec).

Have you tried including the commons-codec JAR in your project?  It may override Android's version.

One thing I tried doing was renaming the commons codec library (meaning there is the old Android library and the newly renamed one).  I then changed the import statements on the ez-vcard source and it seems to have addressed this issue, but this seems like more of a workaround than an actual solution.

That's what I was thinking of doing if the JAR I gave you didn't work.  I was thinking of including the commons-codec source in my project, and then renaming the packages.

By the way, thank you Mike for developing this library.  I have found it very useful!

Thanks, and thanks for your feedback.  I needed more info on how well ez-vcard works with Android (apparently, the answer is "not so well").

-Mike

Michael Angstadt

unread,
Jun 11, 2013, 10:07:41 AM6/11/13
to ez-vcard...@googlegroups.com
Hello!

Just wanted to check in and ask if you were able to get it working?  I am very interested in hearing about how well ez-vcard works with Android.

Thanks,
Mike

web.app...@gmail.com

unread,
Jun 12, 2013, 6:42:34 PM6/12/13
to ez-vcard...@googlegroups.com
Mike,

Sorry, I had forgotten about this!




Have you tried including the commons-codec JAR in your project?  It may override Android's version.

Yes, I also tried this and it still gave me the compile error at runtime.



Thanks, and thanks for your feedback.  I needed more info on how well ez-vcard works with Android (apparently, the answer is "not so well").

 
From what I can tell, this library conflict was the only issue I ran into.  My solution was I downloaded the commons-codec source files and then renamed the package.  I then updated the import statements in the ez-vcard src.  As a result, there were no more conflicts with the commons-codec.

So far, everything seems to be working correctly.  I can both parse and build Vcards.  But keep in mind that my project doesn't really ever deal with VCARD user pictures.  In fact, before I had run into this issue, I had never even included the commons-codec dependency in my project.  So I was still able to parse and build VCards without pictures up until that point.  It was just when I ran into some VCards with user pictures in them that it finally began to complain about commons-codec.

Michael Angstadt

unread,
Jun 13, 2013, 1:32:31 PM6/13/13
to ez-vcard...@googlegroups.com
I'm going to do that as well.  I'll be including the changes in the next release.  Thanks again for bringing this issue to my attention.

-Mike

Michael Angstadt

unread,
Jun 18, 2013, 7:24:10 AM6/18/13
to ez-vcard...@googlegroups.com
Hi,

I've released a new version that contains this fix. Thanks for letting me know about it.

-Mike

Reply all
Reply to author
Forward
0 new messages