Android libraries not found - android

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;

Add these two dependency
compile "org.apache.httpcomponents:httpcore:4.2.4"
compile "org.apache.httpcomponents:httpmime:4.3"
It will work.

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

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:
Then select Java Build Path from the pop up window:
and now select the 'Libraries' tab:
and click on 'Add external JARS' and navigate to your ADT bundle/sdk/tools/lib/httpclient (httpmime etc), and then just click open:
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!

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.

try to download it from HttpClient Downloads

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

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.

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.

Related

Import "MPChartLib" Library to Eclipse

I tried to add "MPAndroidChart" library in Eclipse but when I try to import this lib:(https://github.com/PhilJay/MPAndroidChart/archive/master.zip) .
Amongst the downloaded files , I found a folder called "MPChartLib". This is the actual library folder, I need to add this folder to my project to be able to use the full functionality of the library.
I tried to import the library folder into my workspace, using File-->Import-->Android-->Existing Android but I have this message " Select at least one project eclipse import" !!!!
The lib uses gradle, because of that you can't "import a eclipse project"
You have 2 options, install a gradle plugin for eclipse, or use the lib as a jar
From the lib README:
Download the latest .jar file from the releases section
Copy the mpandroidchartlibrary-.jar file into the libs folder of your Android application project
Start using the library
I hope the same named file is already there or else you can do one thing check the file name to the New Project Name column and check the same file name in your workspace. I must say you that the same named file is definitely there.
So once you will find this, just rename your file name into your workspace and try again importing this.
I hope this will work for you. Any help will be needed, do let me know.
"Select at least one project eclipse import" this message inform you that you have already added Lib in Work Space check for already added "MPChartLib" Lib followed this step:-
Write click on your project and select Properties.
On left select Android.
In Android->Library section click Add
Select for "MPChartLib" (note: name can be change).
Or If you unable to find lib please make new workspace if possible then import MPAndroidChart on workspace.

Android install external library

I want to use this library https://github.com/koush/ion in my project.But I don't understand how can I install it.I am using Windows 8 and Eclipse.How can I install ?
Download that project and put it in workspace of eclipse and import it from work space to eclipse and make it as library project and add it to your project.
Steps to import:
Right Click on package explorer
Import
Existing Project into Workspace
And then browse to the location where the project downloaded
Import it
Steps to add it as library to your project:
Right-click on your project -> Properties
In Android->Library section click Add
Select recently added project -> OK
That's it!
Now you can use it
You must perform the following steps:
Download ion project code.
Import it in your workspace using eclipse.
Right click in your current project and select Properties. The project properties windows must be opened.
Select Android option.
Go to the bottom of this tab and you can view the Library section.
Add the library dependency using the Add button.
I hope that helps!
You are probably better off downloading the jars vs the source.
https://github.com/koush/ion#get-ion
Download those two and place them in the "libs" directory of your project. If that directory does not exist, create it. From with your Eclipse project preferences, you can add those jars as dependencies.

How to resolve javax.xml.bind.* imports in Eclipse? [duplicate]

In my Android app I use:
import javax.xml.bind.JAXBContext;
But I get:
The import javax.xml.bind cannot be resolved
I do have com.viewstreet.java.eclipse.jaxbplugin.JAXBPlugin in my plugins list.
#commonsware is correct , just add respctive JAXB API jars in lib folder of your projet or in case of maven project add dependency in pom file
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
viz in my case on linux, solved the issue
Go to https://javaee.github.io/jaxb-v2/ and download the standalone distribution (link at the very bottom of page).
jaxb-ri-2.3.1.zip or whatever version is the latest shall be downloaded. Unzip it and copy the jaxb-ri\mod\jaxb-api.jar from the unzipped folder into the plugins folder of your eclipse installation directory.
Go to eclipse, open your project, right click project name in Projects panel (left most) and choose Properties => Build Path
Under Libraries tab, select Classpath and then click Add External JARs button. Browse and select the file you just copied to eclipse's plugins folder.
Click Apply and Close
Just import your required javax.xml.bind classes and your project shall be built instantly.
Put the JAR in the project's libs/ directory, then add it to the build path via the Add JARs button. That's my standard recipe, and it seems to work, and it has the advantage of putting the JAR in the right spot for command-line builds as well.
At this point, though, I suspect that you will get a compile error. Generally, you cannot import classes in the java and javax packages into an Android project.
Download jax-b.jar and add it as external jar in your project.
Any import cannot be resolved in Java means a class you referenced is not found anywhere on the classpath. You need the library you're trying to use added to your classpath. In Eclipse, that's in project properties in the Java Build Path => Libraries tab. If you don't have the jar file that contains the API you're trying to use, you probably need to get it from http://jaxb.java.net/.
Adding a library/JAR to an Eclipse Android project

Why can't android find com.google.gson.Gson

I'm trying to use GSON in my project, but my application is crashing, with logcat saying that com.google.gson.Gson cannot be found. I've put import com.google.gson.Gson on my class files, I have gson in my package explorer, and added it by Right click -> build path -> add libraries. It also shows up in Project->properties->java build path->libraries tab->gson. What have I done wrong?
What worked for me: Check the checkbox next to the lib (gson-2.0.jar) in: 'Project Properties' -> 'Java Build Path' -> 'Order and Export' tab. Then do a clean/build.
This adds the exported=true attribute to the classpath entry
<classpathentry exported="true" kind="lib" path="libs/gson-2.0.jar"/>
Have you put the jar file in the libs folder of the project? If not , try moving it there, creating the folder if required. Should be at the same level as the src folder.
I had a similar issue trying to get an app built and that solved it.
I'm using IntelliJ, not eclipse but here is how I did it:
Download the source files from https://google-gson.googlecode.com/files/google-gson-2.2.4-release.zip
Unpack them
Copy them into the "libs" folder of your project. I did this manually by using the terminal but you can do it by going in your project folder located in your computer. Your Project_Name >app >Libs [paste them here]
Go to your editor (IntelliJ in my case) You should see the the following 3 files in the libs folder of the project structure:
gson-2.2.4.jar
gson-2.2.4-javadoc.jar
gson-2.2.4-sources.jar
Open your build.gradle file and insert the following line in the dependencies section:
compile files('libs/gson-2.2.4.jar', 'libs/gson-2.2.4-javadoc.jar', 'libs/gson-2.2.4-javadoc.jar')
Right click on each of the source files and select "Add as Library..."
Use the following options:
Name: name of the jar file
Level: Project Library
Add to Module: select project your adding to
Rebuild project
Build > Rebuild project
Import and use it!
import com.google.gson.Gson;
I have observed today that it doesn't like when you add your library.
The solution that worked for me was to add it as an external jar only. I have observed it by doing the steps described by author of this post i.e. Properties -> Java Build Path -> Libraries -> Add External JARs and point to the downloaded gson library.
I ran into the same issue (when installed SDK 17) ...
The solution is, that you just put the pure jar files into the "libs" folder (without subfolders).
You also don't need to declare them, android wil find them itself. You may need to do a Project > Clean
I had similar problem, but I guess my requirement was more complicated as the GSON libarary was used by an Android Library Project that my main Android project depended on. I have tried both approaches above but none of them worked for me. If I add the GSON jar file directly to the main Android project it works, but that is not what I wanted.
With a bit of investigation I have realised that the GSON jar does not use any dependencies (third party libraries) itself. So my solution was to copy the source file of the GSON project to my Android Library project's src filder and it worked like a charm. so you can use the Source code rather then the binary code. The source code is part of the download in a jar file, just unzip it.
i'm sure you have copied the jar into "libs",
and also added property> Java Build Path >(tab) Libraries, right?
my issue was stupid...
please check other than Gson jar, if you have two stuffs at least in above tab:
android x.x
Android Dependencies (especially this one, i missed this, eclipse show me an error of "could not find class com.google.gson.xx" )
simply do a project copy will solve this problem...
Do not edit .classpath file directly or even put files into lib folders out of Eclipse.
Instead use the Java Build Path->Order and Export tab to select libraries to be exported in the final deployment unit (eg war/apk)
To be on safer side, do a Project->Clean after you change the build path.
I faced the same thing.But the solution was quite easy,just Right-Click on your project->Properies->Libraries->Add external jars->OK and thats it.It solved my problem.hope it will solve yours as well
If Projct Properties -> Java build path -> Add external jars doesn't work and your project is a web project, try adding the gson jar directly to the server lib folder. Example: for apache Tomcat to apache-tomcat/lib.
I have been trying the same thing and read so many answers and tried so many things but to not vial, but i solved this problem by doing just one click and its simple.
1) Add your .jar file in libs folder make sure its libs not lib
2) Clean and Build your project you will see that file under libs folder
3) right click the file and go to build path and select add to build path
Run your project it will work fine. Hope this helps
I am using Android Studio
I had the same problem I had solve it by
select project press f4 from popup
click app and in dependencies
select file dependency and select the three folders which I had pasted in lib directory

How to resolve javax.xml.bind.JAXBContext in Eclipse?

In my Android app I use:
import javax.xml.bind.JAXBContext;
But I get:
The import javax.xml.bind cannot be resolved
I do have com.viewstreet.java.eclipse.jaxbplugin.JAXBPlugin in my plugins list.
#commonsware is correct , just add respctive JAXB API jars in lib folder of your projet or in case of maven project add dependency in pom file
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
viz in my case on linux, solved the issue
Go to https://javaee.github.io/jaxb-v2/ and download the standalone distribution (link at the very bottom of page).
jaxb-ri-2.3.1.zip or whatever version is the latest shall be downloaded. Unzip it and copy the jaxb-ri\mod\jaxb-api.jar from the unzipped folder into the plugins folder of your eclipse installation directory.
Go to eclipse, open your project, right click project name in Projects panel (left most) and choose Properties => Build Path
Under Libraries tab, select Classpath and then click Add External JARs button. Browse and select the file you just copied to eclipse's plugins folder.
Click Apply and Close
Just import your required javax.xml.bind classes and your project shall be built instantly.
Put the JAR in the project's libs/ directory, then add it to the build path via the Add JARs button. That's my standard recipe, and it seems to work, and it has the advantage of putting the JAR in the right spot for command-line builds as well.
At this point, though, I suspect that you will get a compile error. Generally, you cannot import classes in the java and javax packages into an Android project.
Download jax-b.jar and add it as external jar in your project.
Any import cannot be resolved in Java means a class you referenced is not found anywhere on the classpath. You need the library you're trying to use added to your classpath. In Eclipse, that's in project properties in the Java Build Path => Libraries tab. If you don't have the jar file that contains the API you're trying to use, you probably need to get it from http://jaxb.java.net/.
Adding a library/JAR to an Eclipse Android project

Categories

Resources