Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for JsonDocument on Android #65

Open
menew opened this issue Dec 23, 2012 · 4 comments
Open

Support for JsonDocument on Android #65

menew opened this issue Dec 23, 2012 · 4 comments
Assignees

Comments

@menew
Copy link

menew commented Dec 23, 2012

mechanize for Java works correctly with HtmlDocument for HTML pages, but warnings below will be shown in logcat when instantiating MechanizeAgent.

Could not find method org.json.JSONTokener.<init>, referenced from method com.gistlabs.mechanize.document.json.JsonDocument.loadPage
VFY: unable to resolve direct method 5608: Lorg/json/JSONTokener;.<init> (Ljava/io/Reader;)V

Because of this class loading error, JsonDocument is not available on Android. Following exception will be thrown when loading JSON pages (like https://www.googleapis.com/urlshortener/v1/url).

FATAL EXCEPTION: main
java.lang.NoSuchMethodError: org.json.JSONTokener.<init>
at com.gistlabs.mechanize.document.json.JsonDocument.loadPage(JsonDocument.java:40)

This error may be caused by limitation of Android. Android does not support org.json library fully (or uses too old version), so lacks JSONTokener(java.io.Reader) constructor.

http://developer.android.com/reference/org/json/JSONTokener.html#pubctors

I'm currently using mechanize with patch to import another org.json library in another namespace (built and placed by hand), but I hope this problem be solved in master branch.

@ghost ghost assigned jheintz Apr 25, 2013
@jheintz
Copy link
Member

jheintz commented Apr 25, 2013

Wow, Android is using the 2007 version of org.json. That's very annoying.

I almost wonder if we should/could package many of these dependencies right into the jar for mechanize (at least for an android version.) Possibly the maven shade plugin...

@jheintz
Copy link
Member

jheintz commented Apr 25, 2013

I've used the maven shade plugin to try to resolve this issue (by embedding the latest org.json code into the mechanize jar as org.shaded.json).

Here's a download link for this variation of the mechanize library:
https://dl.dropboxusercontent.com/u/2169154/mechanize-android-0.11.1-SNAPSHOT.jar

I still need to figure out how to effectively publish this... I'd like this variation of the library to be in the maven repos as a mechanize jar in the context of android. At least I think that's what I want...

@jheintz
Copy link
Member

jheintz commented Apr 25, 2013

Not context, but classifier.

Here is a link that might contain the details for how to publish different ways based on profiles:
http://www.sonatype.com/people/2010/01/how-to-create-two-jars-from-one-project-and-why-you-shouldnt/

@jheintz
Copy link
Member

jheintz commented Apr 25, 2013

The latest code seemed to work, I've published the main artifact and also an "android" classifier that includes the shaded org.shaded.json package.

Here's the maven dependency:

<dependency>
  <groupId>com.gistlabs</groupId>
  <artifactId>mechanize</artifactId>
  <version>0.11.2-SNAPSHOT</version>
  <classifier>android</classifier>
</dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants