AndroidHttpClient not found (when running Robolectric)

AndroidHttpClient was removed from the SDK in v23 of the build tools.

As Robolectric is running against earlier versions, it expects it to be there, which is why you’re seeing this error.

For now, you can add it back in:

android {
    useLibrary 'org.apache.http.legacy'
}

As detailed here.

There is a GitHub ticket open for Robolectric to fix this. You can follow the thread/ticket here.

Update:

As some people have correctly pointed out, a better way of doing this would be to create a class android.net.http.AndroidHttpClient in your test resources. This would be a preferred method because you’re only modifying the test sources, not the production code, in order to accommodate the tests.

I’ve just added fake class android.net.http.AndroidHttpClient in my test sources. And it solved the issue for now. Waiting for Robolectric to be updated

Apparent problem and solution:

AndroidHttpClient was removed from the SDK in API Level 23, while Robolectric was set to run tests with SDK 21:

AndroidHttpClient was removed from the SDK in API Level 23