views:

20

answers:

2

I'm currently trying to run some unit tests on a class that uses HTTPtransport and is part of an Android application. The docs for google-api says that this should be fine since the Apache transport is built into Android.

However, when running my tests I get the following error:

java.lang.IllegalStateException: unable to load NetHttpTrasnport at com.google.api.client.http.HttpTransport.useLowLevelHttpTransport(HttpTransport.java:98) at com.google.api.client.http.HttpTransport.(HttpTransport.java:156) at com.google.api.client.googleapis.GoogleTransport.create(GoogleTransport.java:58) at uk.co.redfruit.android.whogotwhat.googlebase.GoogleBaseSearch.search(GoogleBaseSearch.java:41) at uk.co.redfruit.android.whogotwhat.test.GoogleBaseSearchTest.testSearchForBarcode(GoogleBaseSearchTest.java:22) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

Is this a bug? Or am I just missing something?

A: 

Is it possible that you are using version 1.1 of the library? I just fixed a bug to make the Apache transport the default in version 1.2. So if you're using version 1.1, please try switching to 1.2 and let me if that doesn't resolve the error.

Disclaimer: I'm an owner of the google-api-java-client library.

Yaniv Inbar
It is 1.2 I'm afraid - I only downloaded and started using it today. Liking it so far though - current problem aside!
Paul Hunnisett
I'm assuming (perhaps incorrectly) that its something to do with it being run in a testing context. Unfortunately my app isn't complete enough yet for me to try the code stand alone in Android.
Paul Hunnisett
Any ideas? It does look as if that bug is not completely resolved... I've checked again - definitely using 1.2
Paul Hunnisett
A: 

OK - I figured out the problem. Due to the way you're trying to determine which environment you're in (using class.forName() and catching Exception) all classpath errors will cause this to fail - which can be misleading.

It was correctly determining my environment (so this was nothing to do with Unit Tests), but then failed to load some other classes.

By adding the apache client, repackaged and escape jars I was able to fix the problem. I would suggest that this could perhaps be improved upon.

Paul Hunnisett