Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference an external jar in an Android Library project in Eclipse

Tags:

android

Oh Android. How I love your verbiage.

I have a workspace with a few projects in it. App1 and App2 are Android applications. Common is an Android library project. App1 and App2 depend upon Common (linked via the Android tab).

Common has some external dependencies, namely httpmime & apache-mime4j, which exist as jar files.

For some reason, it appears that I need to add my mime jars to the build path of App1 and App2 for compilation to succeed. This seems really dumb. In normal Java, I would add Common to the build path of App1 and App2 and things would work. Is this expected that I have to add my jars to every Android application?

-Andy

Note: If I don't configure the build path as described above, I get "The type org.apache.james.mime4j.message.SingleBody cannot be resolved. It is indirectly referenced from required .class files | DataCallUtil.java | /App1/Common/util | line 364"

like image 671
Andy V Avatar asked Sep 13 '10 23:09

Andy V


2 Answers

I think omermuhammed and Amit didn't get the fact that Visser is talking about a Android Library Project. For those project, I don't think it is possible to create a jar. ( jar has nothing to do with all the Android resources thing ).

From my experience with Android Library Project, this kind of project are just, basically, the sources and the ressources packaged, and ready to be included in another project. But the settings are not part of the package, so you have to include the libs for each application. In my experience, this setting is not something that changes often, so it is not so bad.

Android Library Project are still way from being perfect, but still a huge improvement from what was there before ( ie nothing ).

like image 158
alocaly Avatar answered Nov 18 '22 05:11

alocaly


To augment omermuhammed's reply, if the common project is not one that is being changed frequently, creating a jar and using it in the other projects is a good solution.

To create a jar right-click the project on Eclipse -> Export -> Java -> JAR file, then select the folders you want to include in the JAR, in your case I guess this includes the folders gen and libs (libs being the folder with the httpmime & apache-mime4j JARS), but probably neither res nor the root directory of your project (with files such as AndroidManifest.xml that will cause problems with the same file in the dependent projects).

like image 1
Amit Kotlovski Avatar answered Nov 18 '22 04:11

Amit Kotlovski