qwerty
qwerty

Reputation: 5246

Java/Android: How do you properly import a library in Eclipse?

I'm working on an Android project and i need to import an XML library called XOM. The only way i found was to right click on the project name -> Properties -> Libraries tab -> click on "Add external Jar". But that only references it from it's original path, what happens when i compile the app and move it to my phone? Will the Jar be in there?

Might be a stupid question, sorry if that's the case.

Upvotes: 1

Views: 639

Answers (3)

AnujAroshA
AnujAroshA

Reputation: 4811

Create a directory called "libs" in your under your root directory. You can do it by,

  • Right click on the project which is in the Package Explorer window in Eclipse.
  • New -> Folder -> give "libs" as the Folder name
  • Copy your jar file and paste it to in the "libs" folder
  • Expand the "libs" folder
  • Right click on your copied jar file -> Build Path -> Add to build path

That's it

Upvotes: 0

N-JOY
N-JOY

Reputation: 7635

.apk is nothing but a collection or zipped version of a file. it contains all the resources and compiled java files.
So you need not have to worry about the inclusion of your library files. if you have set proper path to your libraries in eclipse then these will be included in your apk file.

Upvotes: 0

Aidanc
Aidanc

Reputation: 7011

It's fine to do that but what I normally do is create a folder called liband then add Jars from there. I find that makes it easier to see what Jars I have in my application.

The main disadvantage of your original approach is that what if the path to that library externally accidentally changes? then your program will not compile. It's better to have everything in the one place to make things easier.

Upvotes: 2

Related Questions