views:

49

answers:

1

As I am very pissed off of using the emulator to develop any Java class, I thought of setting up a project in Eclipse and instead of the usual JRE I linked to the Android.jar (version 2.1) that usually the Android projects link to. I don't mean to use this to develop Layouts or other specific platform things, I was just trying to create a class that uses HttpClient. It miserably crashes like this.

Exception in thread "main" java.lang.RuntimeException: Stub! at org.apache.http.impl.client.AbstractHttpClient.(AbstractHttpClient.java:5) at org.apache.http.impl.client.DefaultHttpClient.(DefaultHttpClient.java:7) at AdsCatcher.(AdsCatcher.java:26) at TestAll.main(TestAll.java:10)

Stub! I mean I'd like to develop libraries (and test them) so that when I go to the emulator I don't have to deal with them. Is there a good way to do this? This seems not to work for some reason.

A: 

This will not work, sorry. The android.jar file, as the error message indicates, contains only stubs of the Android API. This makes sense, since that API cannot work outside of Android -- the android.jar file is just there for compilation.

For class libraries you are working on that have no dependencies on Android, you are welcome to create a standard JRE Eclipse project that generates a JAR that you then use in your Android project.

In your case, you may be able to create a class library using the JRE that uses HttpClient. The latest version from Apache may differ slightly from the version in Android, though, so while probably you will be OK, there's a chance you will run into runtime errors due to changes in method signatures and such (VerifyError).

CommonsWare
I was suspecting this, what you say makes a lot of sense... Anyway in this particular case HttpClient is so different that even the basic Apache tutorial is not working on Android :(
gotch4
@gotch4: Make sure you are looking at the HttpClient 4.x tutorial. HttpClient completely overhauled their API between the 3.x and 4.x series.
CommonsWare