0

I am working in Android. I am trying to install dependencies (without maven) for the Unirest library. I have added the exact versions of the dependencies, namely: httpclient 4.3.6, httpmime 4.3.6, httpasyncclient 4.0.2.

However, i am still getting this error:

E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.abdulwasae.odnvt_1, PID: 12678
                                               java.lang.NoClassDefFoundError: org.apache.http.impl.conn.PoolingHttpClientConnectionManager
                                                   at com.mashape.unirest.http.options.Options.refresh(Options.java:72)
                                                   at com.mashape.unirest.http.options.Options.<clinit>(Options.java:46)
                                                   at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:151)
                                                   at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:131)
                                                   at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
                                                   at com.abdulwasae.odnvt_1.ODFragment$2.onClick(ODFragment.java:225)
                                                   at android.view.View.performClick(View.java:4856)
                                                   at android.view.View$PerformClick.run(View.java:19956)
                                                   at android.os.Handler.handleCallback(Handler.java:739)
                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                   at android.os.Looper.loop(Looper.java:211)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5373)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)

According to the relevant Apache Javadocs, this definition was present in the org.apache.httpclient in the version as early as 4.3.

I am stumped. Any help would be appreciated.

Also, here is my gradle snapshot in case it helps:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.abdulwasae.odnvt_1"
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/NOTICE' // will not include NOTICE file
        exclude 'META-INF/LICENSE' // will not include LICENSE file
        exclude 'META-INF/DEPENDENCIES' // will not include DEPENDENCIES file
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile files('libs/unirest-java-1.4.7.jar')
    compile files('libs/httpasyncclient-4.0.2.jar')
    compile files('libs/httpclient-4.3.6.jar')
    compile files('libs/httpmime-4.3.6.jar')
}

UPDATE I checked to confirm if the troubling class could be found in any one of the added dependencies. And, yes, it does show in httpclient-4.3.6.jar

class in httpclient-4.3.6.jar

I wonder what to check next.

2
  • why do you use HttpClient, it 's deprecated, Use HttpUrlConnection. Commented Mar 10, 2016 at 20:22
  • Because it's a dependency requirement Commented Mar 10, 2016 at 20:25

2 Answers 2

1

Use unirest-java-1.4.9-SNAPSHOT-withDependency-ShadedForAndroid. It can be built by following this tutorial.

Sign up to request clarification or add additional context in comments.

1 Comment

does the job for me! ;) However, the issue above remains a mystery
0

NoClassDefFoundError always means you are missing a jar file.

java.lang.NoClassDefFoundError: org.apache.http.impl.conn.PoolingHttpClientConnectionManager

Looks like its in httpcomponent-client, try adding:

 compile 'org.apache.httpcomponents:httpcomponents-client:4.5.2'

to your build file.

8 Comments

Are you sure though? Arent 'noClassFound' and 'noClassDefFound' different?
Use Jarzilla or Zip to open then jar file and look for the class referenced. org.apache.http.impl.conn.PoolingHttpClientConnectionManager If its there then its a classpath problem. If its missing, then keep looking in httpcomponents core of one of the related libs.
Also, I see you're using httpclient, which is a different lib than httpcomponents.
Http components is just a set of many jars including HttpClient. Are you suggesting that i add all of the jars in this set and try?
Ok i will try the jarzilla methid and get back
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.