how to use htmlunit with my android project - android

I have downloaded htmlunit 2.11 zip. i have extract it. then i have tried to paste them in my project's libs folder. from the libs folder i have added them in build path. then i get this error, while i was trying to run my app
conversion to dalvik format failed with error 1
then, from stackoverflow i found that, one said to delete xalan xercesImpl xml-apis.
i deleted them. but getting this error:
Error generating final archive: Found duplicate file for APK: about.html
error message also showed that which files are conflicted. they are jetty-http jetty-io jetty-util jetty-websocket then i run my app again. this time it shows some warning. i have ignored them. but my app crash saying that classNotFound
by the way, i have also deleted httpclient jar. because one said that httpclient is already built in android.
this is my problem. Now, can anyone help me? i really want to use htmlunit in my app
Edited:
it will be very helpfull if you show me the steps, 'how to add htmlunit in my project'
Edited 2:
mainly i have a link, which i have get after login (i have login through web view) this link give me a simple page. in that page there is a textarea and a submit button. and there are some javascript too (i think these javascript run, when i press the submit button). i can do it through webview, but for some reason i don't want to use webview. whene i press submit button, it deliver the value of textarea and some value of hidden field with existing cookies(which are get when i logged in through webview) Post method. i need to do this without webview. now is there any other option beside htmlunit ?? i heard about HttpClient, HttpUrlConnection. one more thing, agter submitting it will redirect me to another page. i don't need to do anything with this redirected page.
N.B: if this question is not appropriate with what i really ask previously, then you can suggest me, and i will post a new question. thank you

Nothing of this will work because he is trying to include HtmlUnit into a android project. HtmlUnit is not compatible with android because is refernces some java.* & javax.* classes which are not available in android.
Hope there will come a version for android.

sorry, i have lost all my hope on HTMLUNIT. :( to gain my goal i have used HttpUrlConnection & Jsoup ... that works for me. here is my procedure i have post my code in answer.

Here are the steps to follow:
Download the latest version of HtmlUnit from http://sourceforge.net/projects/htmlunit/files/htmlunit/2.11/
Unzip downloaded file
Go to lib folder --> Right click on htmlunit-core-js-2.11.jar and select 'copy'
Go to Package Explorer in Eclicse --> Chose your project --> Right click on libs folder and select 'paste'
Right click on the newly added file and click on 'Add as a library...' and select your project.
Repeat steps 3, 4 and 5 for the htmlunit-2.11.jar file
Add this two imports to your project:
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
Clean the project.
Please also check this link http://www.aviyehuda.com/blog/2011/05/16/htmlunit-a-quick-introduction/ for the htmlUnit quick introduction

I know it's too late to answer, but hopefully my answer will help other newbie's like me who is trying to webscrape in their android app and stumbled upon this thread for a working solution of htmlUnit in android studio. I used a previous version of htmlUnit (2.14) and it worked for me. Why I was trying htmlUnit, and not Jsoup ? because my target webpage had javascript calls, which was not giving a fully loaded html. So, in short: Use a previous version of htmlUnit.

Related

Android ActionBarCompat Not working from the start

OK, I have been wanting to try the new ActionBarCompat, however, I am not able to run my programs in the emulator.
I have been trying to implement the following: http://antonioleiva.com/actionbarcompat-how-to-use.
and have been stuck on basically the first part. However, working with the author of that content, I was able to get further as I was not adding the project under sdk\extras\android\support\v7\appcompat folder like stated. However, I still think that might be the reason I cannot do this...
More detail can be found here: http://antonioleiva.com/actionbarcompat-how-to-use/#comment-43
Basically, on my first attempt, I just created an Android project, and changed the source code as indicated. Code would not run on the emulator. So I went back to the original code, and that ran on the emulator.
Checked online, found out I might need to add the \extras\android\support\v7\appcompat folder as a library to the project I am building. So I added that and a new android project was created. There were build errors from the start, but I failed at trying to add it as a library to my project, and deleted it....thinking this was way overboard.
After back and forth chats with author of linked website, I found out I had to do that overboard thing.
So I tried the following link to the T: (I cannot post more than 2 links due to low repuation...I will add this link as a comment below)
However, Eclipse would not allow me to add the appcompat Existing Android Project...but it did allow me to add the appcompat Existing (General) Project. I think this may be some of the problems??
Right now, I cannot run the project at all. Eclipse is showing a red exclamation mark on the project folder, but all the code seems to be fine. So I don't know what to do now...I recreated this project several times over, and this one was the one where I knew what to do...and I am still getting problems
So...
I decided to move to Android Studio...updated the IDE, updated the SDK manager to include the new support library, and other things. Created a new project, added to the build.gradle file as shown in the link provided below in the comment. I ran the ant build, and then built the project...tried to import the right things to allow ActionBarActivity, but I could not get that far.
I can import
"android.support.v7.*"
"android.support.vy.R" // and all folders within
but nothing allows me to add ActionBarActivity, and I don't know why.
FYI, I guess I would prefer a solution to Ecplise, as it seems like I actually got somewhere with it.
The best example to use is from here, and I would follow it closely. I had similiar issues when I first came across this. Problem was I misunderstood what I needed to do
http://developer.android.com/tools/support-library/setup.html#libs-with-res

Problems referencing Facebook SDK in Android app

I have been trying to use FBConnect in my app but whenever I try to reference the SDK, it doesn't quite do it.
This is the screenshot
Please help. I am stuck for past 4 hours. Nothing found on google or here on SO
Refer to this page: http://www.mobisoftinfotech.com/blog/android/845/. Seems like you should add the JAR file. What you did here is add a library - an open project in Eclipse that serves as a library for another project.
Clarification: when you click add, you see "FacebookSDK". It shows as valid until you close the properties dialog. Then when you open the dialog again, it has a red X next to it.
If that is what is happening to you... I ran into the same thing a long time ago. The facebook sdk needs to be in the same parent folder as your project.
For example, if you are running out of c:\users\me\workspace\my cool project,
the facebook sdk needs to be in c:\users\me\workspace\facebook-android-skd-2.0.2.b
No idea why, but after beating my head against the wall over this for a couple of days I figured it out.

Using Jsoup (or other 3rd party jars) in Android

This is the first time I've used a 3rd party jar, but it seems like I'm doing everything right. I'm using Jsoup to parse HTML.
In my project, under Properties->Java Build Path I have added the external jsoup jar. Under Order and Export I have tried jsoup both checked and unchecked. Seems to have made no difference. When writing my app, eclipse was able to find the right imports, autocomplete methods/constructors. Eclipse seems to see Jsoup fine.
However, when I run my app, one of my activities calls methods from Jsoup. Whenever I launch that activity, I get the following error.
Could not find method org.jsoup.parse, referenced from method...
VFY: unable to resolve state method 348: Lorg/jsoup/Jsoup; parse...
Am I not importing it properly? Why can it not find jsoup? The above steps seem to be the answer to all the questions on importing a 3rd party jar to Android in eclipse.
My best guess is that eclipse can see the jsoup.jar, but it does not package up the parts I need with the app, so the app is unable to use them. Not sure if that's it, but if it is, how would I force eclipse to package it so the app can use it from anywhere?
Invoke the Eclipse function Organize Imports by pressing Shift+Alt+O and that should take care of everything.

Android in-app billing example, wrong source files?

I downloaded the Android in-app billing example and imported it into Eclipse. After import I see some strange errors.
There is a source file AccelerometerPlay and the string resources in the Dungeons.java file are not existing.
It seems that the download got the wrong resources. Has anybody seen this and knows how to get the right code?
Of course I can put in my own strings to get rid of the error markers, but I cannot say if something else is missing. So I'd rather have a correct version of the code.
How can I take over this question? It is not resolved for me and I can not up-vote it or comment on it stating this still persists for me. Duplicating the question can't be the solution neither.
More details:
The Dungeons example is not in "Extras/Google Market Billing Package" as shown in the screenshot in their tutorial but in "Extras/Google Play Billing Library"
The version of this is "revision 2".
After removing it via the Android SDK Manager various times and adding it again to re-create the project from source within Eclipse, I now did check the "create Activity .Dungeon" checkbox in the last step and think that did the trick. I'm not eager to verify this assumption ending up without a broken project again though.
In Eclipse and Intellij, if you create a new app over those existing sources (and presumably have it create a default activty like "MyActivity") it will overwrite some of the billing files namely the main layout and the strings file.

Facebook SDK not included with Android App in Eclipse?

I'm trying to add the facebook SDK to my project but it won't work at all.
I've followed the official steps; opened the fb sdk, made sure it's set to "is library", in m yown project go to properties->android->add library and it lets me select com_facebook_android and it shows up with a green tick next to it. HOWEVER, when i go back to that screen straight away it now has a red cross next to it, and if i try to launch the app in the emulator it has " com_facebook_android] Could not find com_facebook_android.apk!"
(This is just me testing without referencing the library in my app)
if i DO reference the library, then any calls to the facebook library give an error within eclipse and the tooltip suggests to add it to build path, so if i click that it launches fine, but still does the above apk error and the app force closes on any activity which references facebook.
As far as I can tell I'm following the official instructions fine but it just keeps coming back to that red cross in my app's properties
Does anyone know what this could be?
Not sure why you have the issue, i've setup a empty project with facebook library in it, if you have no luck then try downloading that, unzipping it and importing exsiting project into workspace.
link : Download here
you know what i have done one trick to use the official facebook SDK in my application, i have created com.facebook.android and add all the library classes into it. Then i can easily reach to access any class whenever i want it. This can be a way to use the classes inside your application instead of using Library.
Its running fine in my case.

Categories

Resources