Rajeev
Rajeev

Reputation: 46979

Android libraries not found

In my android project I am writing a program to connect to a server and below are the libraries that I need to use.

But I get an error saying the following cannot be resolved. How to resolve this error? I am using eclipse JAVA EE on Windows.

 import org.apache.http.entity.mime.MultipartEntity;
 import org.apache.http.entity.mime.content.ContentBody;
 import org.apache.http.entity.mime.content.FileBody;
 import org.apache.http.entity.mime.content.StringBody;

Upvotes: 17

Views: 40878

Answers (8)

Ankish Jain
Ankish Jain

Reputation: 11361

Add
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.3.4.jar') to your build.gradle.

Before that download .jar from http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/ http://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime

and to your apps>lib folder.

Upvotes: 0

MindBrain
MindBrain

Reputation: 7768

If you are using android studio add the following import to your code:

import org.apache.http.entity.mime.content.FileBody;

The IDE will give you an error under "mime" and ask you if you would like to install the dependancy. So if you say yes it will search for it online and then you can download it to app/build/libs directory. FileBody will then be recognized after this process is complete.

Upvotes: 0

Sanjay Jain
Sanjay Jain

Reputation: 681

Add these two dependency

compile "org.apache.httpcomponents:httpcore:4.2.4"
compile "org.apache.httpcomponents:httpmime:4.3"

It will work.

Upvotes: 27

Mick
Mick

Reputation: 25511

I know this is an old thread but it make be worth mentioning that these jars are now included in the eclipse Android ADT bundle (for MAC anyway, I have not checked for Windows). You do need to check the version is the one you want, but if it is you are good to go.

This means you can add them to your project without having to download them separately first - just follow these steps:

First right click your project and select properties as shown below:

enter image description here

Then select Java Build Path from the pop up window:

enter image description here

and now select the 'Libraries' tab:

enter image description here

and click on 'Add external JARS' and navigate to your ADT bundle/sdk/tools/lib/httpclient (httpmime etc), and then just click open:

enter image description here

You also need to import the Jar file itself into your project. I found the best way to do this was to simply copy the JAR files into the 'libs' folder in your project - i.e. CTRL C and CTRL V, or normal drag and drop file copy. To be safe I would refresh (right click project and select refresh - see menu in first picture above) and then clean your project.

Note if you do the Build Path part above correctly but forget to add the JAR files themselves into your 'libs' folder, you will get an error like: 'Caused by: java.lang.NoClassDefFoundError: org.apache.http.entity.mime.content.FileBody'.

To resolve this just copy the jar files into the 'libs' folder in your project.

You should now be good to go!

Upvotes: 12

MByD
MByD

Reputation: 137442

Download the jars from the apache commons site and add them to project and path.

[Edit] now in Apache HttpComponents http://hc.apache.org/downloads.cgi

Upvotes: 18

Nishant
Nishant

Reputation: 93

Download the JAR file "httpmime-4.0-beta2.jar" and add it to your project

Upvotes: 0

Sumit
Sumit

Reputation: 746

download the jar from here : http://commons.apache.org/

install it in your project like this:

Right click on your project and go to properties. On the left tab go to "java build path". And in that on right go to libraries. Click on add external jars and give the path of the jar and your library is added.

Upvotes: 3

Mohammad Ersan
Mohammad Ersan

Reputation: 12444

try to download it from HttpClient Downloads

Upvotes: 2

Related Questions