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.
I'm currently using SDK 20.0.3 and none of the previous solutions worked for me.
The reason that hessdroid works where hess failed is because the two jar files contain java that is compiled for different virtual machines. The byte code created by the Java compiler is not guaranteed to run on the Dalvik virtual machine. The byte code created by the Android compiler is not guaranteed to run on the Java virtual machine.
In my case I had access to the source code and was able to create an Android jar file for it using the method that I described here: https://stackoverflow.com/a/13144382/545064
Turns out I have not looked good enough at my stack trace, the problem is not that the external JAR is not included.
The problem is that Android platform is missing javax.naming.* and many other packages that the external JAR has dependencies too.
Adding external JAR files, and setting Order and Export in Eclipse works as expected with Android projects.
I know the OP ends his question with reference to the Eclipse plugin, but I arrived here with a search that didn't specify Eclipse. So here goes for Android Studio:
jar
file to libs directory (such as copy/paste)jar
file and select "Add as Library..."That's it!
Copying the .jar file into the Android project's folder isn't always possible.
Especially if it's an output of another project in your workspace, and it keeps getting updated.
To solve this you'll have to add the jar as a linked file to your project, instead of importing it (which will copy it locally).
In the UI choose:
Project -> Import -> File System -> yourjar.jar -> (Options area) Advanced -> Create link in workspace.
The link is save in the .project file:
<linkedResources>
<link>
<name>yourjar.jar</name>
<type>1</type>
<locationURI>PARENT-5-PROJECT_LOC/bin/android_ndk10d_armeabi-v7a/yourjar.jar</locationURI>
</link>
</linkedResources>
PARENT-5-PROJECT_LOC
means relative to the project file, 5 directories up (../../../../../).
Then add it to the libraries:
Project -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.jar
In the same window choose the Order and Export tab and mark your jar so it will be added to the apk.
Goto Current Project
RightClick->Properties->Java Build Path->Add Jar Files into Libraries -> Click OK
Then it is added into the Referenced Libraries File in your Current Project .
If you are using gradle build system, follow these steps:
put jar
files inside respective libs
folder of your android app. You will generally find it at Project
> app
> libs
. If libs
folder is missing, create one.
add this to your build.gradle
file your app
. (Not to your Project
's build.gradle
)
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// other dependencies
}
This will include all your jar
files available in libs
folder.
If don't want to include all jar
files, then you can add it individually.
compile fileTree(dir: 'libs', include: 'file.jar')