13

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"

Andy V
  • 987
  • 11
  • 16

3 Answers3

8

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 ).

alocaly
  • 697
  • 6
  • 7
  • 2
    +1 for clarifying that `"the settings are not part of the package"`. – an00b Jun 13 '11 at 16:49
  • @alocaly +1 any updates on this? Is there a way not to include the referenced jar files of the library project into every android application project? By the way, It is possible to create a android jar file by utilizing Custom Ant Build but still need to include the referenced jar files into application projects :( Regards. – eros Aug 29 '11 at 02:44
1

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).

Amit Kotlovski
  • 1,848
  • 1
  • 18
  • 13
0

Try compiling the Common project into a jar and adding it as an external jar to your App1 or App2 projects.

omermuhammed
  • 7,365
  • 4
  • 27
  • 40
  • How do I do that? The docs (http://developer.android.com/guide/developing/other-ide.html#libraryProject) state, "However, a library project differs from an standard Android application project in that you cannot compile it directly to its own .apk or run it on the Android platform. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library from a dependent application's build path, then building that application." – Andy V Sep 14 '10 at 19:39
  • Compile the common project into a jar, copy it into "lib" folder under your android project, then, in eclipse, rightclick android project - > Build Path - > Configure Build Path. Now, in the left panel select "Java Build Path". Now under "Library" panel, click on "Add External Jars" and add your jar. Save and compile. It should work. Also dont forget to add the required line to your AndroidManifest.xml with tag " – omermuhammed Sep 14 '10 at 20:05
  • I understand the process you are talking about. But your first 7 words, "Compile the common project into a jar." How? Write some custom Ant to do that? I'd rather do what I'm doing and have to add the dependency everywhere. This is something I expect Eclipse to do nicely. If it doesn't, that's fine. I'd just like to know it's a shortcoming with Android/Eclipse. – Andy V Sep 15 '10 at 18:20