Android libraries not found

2020-02-04 07:35发布

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;

8条回答
一纸荒年 Trace。
2楼-- · 2020-02-04 08:12

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!

查看更多
\"骚年 ilove
3楼-- · 2020-02-04 08:15

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.

查看更多
趁早两清
4楼-- · 2020-02-04 08:17

try to download it from HttpClient Downloads

查看更多
Fickle 薄情
5楼-- · 2020-02-04 08:19

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

查看更多
劫难
6楼-- · 2020-02-04 08:19

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.

查看更多
霸刀☆藐视天下
7楼-- · 2020-02-04 08:22

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

查看更多
登录 后发表回答