I have created an Android project and added an external JAR (hessian-4.0.1.jar) to my project. I then added the JAR to the build path and checked it off in Order and Export.
create a folder (like lib) inside your project, copy your jar to that folder. now go to configure build path from right click on project, there in build path select
'add jar' browse to the folder you created and pick the jar.
in android studio if using gradle
add this to build.gradle
compile fileTree(dir: 'libs', include: ['*.jar'])
and add the jar file to libs folder
Yes, you can use it. Here is how:
This video might be useful in case you are having some issues.
Android's Java API does not support javax.naming.* and many other javax.* stuff. You need to include the dependencies as separate jars.
If using Android Studio, do the following (I've copied and modified @Vinayak Bs answer):
- Select the Project view in the Project sideview (instead of Packages or Android)
- Create a folder called libs in your project's root folder
- Copy your JAR files to the libs folder
- The sideview will be updated and the JAR files will show up in your project
- Now right click on each JAR file you want to import and then select "Add as Library...", which will include it in your project
- After that, all you need to do is reference the new classes in your code, eg.
import javax.mail.*
For Eclipse
A good way to add external JARs to your Android project or any Java project is:
libs
in your project's root folderlibs
folderNow right click on the Jar file and then select Build Path > Add to Build Path, which will create a folder called 'Referenced Libraries' within your project
By doing this, you will not lose your libraries that are being referenced on your hard drive whenever you transfer your project to another computer.
For Android Studio
Please Note : If you are using 3rd party libraries then it is better to use transitive dependencies where Gradle script automatically downloads the JAR and the dependency JAR when gradle script run.
Ex : compile 'com.google.android.gms:play-services-ads:9.4.0'
Read more about Gradle Dependency Mangement