Jakob Bjerre Jensen
Jakob Bjerre Jensen

Reputation: 429

Best Android practice for referencing a .jar file

Consider the situation with an Android library project A, which depends on a file B.jar.

Now I want to setup an Eclipse development environment as well as a command line environment. What is the best approach? Should I:

  1. reference the B.jar file directly from Eclipse (Properties -> Java Build Path -> Libraries)? But how can I make this to work in the command line environment?
  2. create an Android library project using android create lib-project consisting of only B.jar (if that is possible) and reference this wrapper project using android update project --path A --library B? Further use Properties -> Java Build Path -> Libraries to make the reference in Eclipse.
  3. from Eclipse create an Android project and only add B.jar to it (I am not sure how). How do I make this work in the command line environment?

Further creating a library project, which depends on other .jar files, should this be distributed as individual .jar files or one single .jar file containing the others?

Upvotes: 0

Views: 181

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007369

reference the B.jar file directly from Eclipse (Properties -> Java Build Path -> Libraries)?

Absolutely not, as that does not work for Eclipse, let alone command-line. While you will compile, your app will not ship the contents of the JAR, and you will crash at runtime.

create an Android library project using android create lib-project consisting of only B.jar (if that is possible) and reference this wrapper project using android update project --path A --library B?

Um, you could, though that would seem to be overkill.

from Eclipse create an Android project and only add B.jar to it (I am not sure how)

Put the JAR in the libs/ directory of the project.

How do I make this work in the command line environment?

Put the JAR in the libs/ directory of the project. The libs/ directory is added to the compile path for both Eclipse and command-line builds, and the contents of libs/ is added to your Android APK.

Upvotes: 3

Related Questions