2

The title might seem confusing (although accurate). Let me explain it in more words:

I have an android Library project, lets call it ProjectA. I also have second android Library project, lets call it ProjectB. The ProjectB and ProjectA are in the same workspace, and ProjectB is referencing ProjectA in it's libraries list (project properties). So ProjectB is using ProjectA.

Now what I want to accomplish is to get a simple jar of the library - ProjectB, and include this jar as external library in my yet another android project (android application this time).

However... when I compile ProjectB, the jar size is way too small (the ProjectA's jar is over 300KB, yet ProjectB's jar is only 14KB), so I'm sure it does not contain ProjectA's in the jar file I find inside bin folder (of the ProjectA). To do a quick math, ProjectB's jar should be ~300KB bigger.

So to repeat, I'd like to have everything the library needs, packed in one jar file (jar file of ProjectB's), so that when I import it into libs of an Android Application I can use it.

Any help here from expierienced Android dev?

Lucas
  • 3,521
  • 3
  • 27
  • 39
  • possible duplicate of [How to combine two Jar files](http://stackoverflow.com/questions/5080220/how-to-combine-two-jar-files) and http://stackoverflow.com/questions/882204/merging-multiple-jars-in-to-a-single-jar and http://stackoverflow.com/questions/14350150/how-to-combine-multiple-jars-into-one and countless more. Note, though, that you can only create a simple JAR of an Android library project if that project does not contain resources. – CommonsWare Nov 27 '13 at 21:53
  • From what I see, all those topics you mentioned concern non-android projects. As I learned, those are treated specialy, and thus I need a solution that works exactly with Android application project in connection with Android Library Projects. I already tried couple solutions others have mentioned (in java related projects), but were not appliable in my scenario I explained above. – Lucas Nov 28 '13 at 08:47
  • 1
    Since you are manually creating your JARs from your Android library projects, they should merge like any other JARs. There is no other way to get a JAR from an Android library project in a reliable fashion, other than by creating it manually. And, as I previously noted, if you are trying to convert an Android library project with resources into a JAR, that is not possible, let alone your objective of merging. – CommonsWare Nov 28 '13 at 12:17
  • I'm compiling an android project, and getting a jar from it's bin folder. Not doing anything manual besides that. Are you talking about a simple built as "creating jar manually"? If no, please explain. As for resources, I understand and am aware of this limitation. Lets clarify, that I'm speaking about library projects without resources. – Lucas Nov 28 '13 at 15:38
  • 2
    "and getting a jar from it's bin folder" -- that is not for your use. That is only for the Ant/Eclipse build process when attaching your library project to a hosting application. It is not a first-class build artifact in its own right. Hence, do not complain when that JAR perhaps does not behave the way that you want, and do not complain if that JAR is no longer saved for you in the future. If you want a JAR file, make one yourself. JAR files have been around for ~15 years, and there are plenty of instructions online for creating them. – CommonsWare Nov 28 '13 at 15:41
  • I was not and am not complaining. I'm trying to understand my options, that's all. If that's a limitation I will live with that. So, to clarify, I should NOT take a jar from bin folder of a library project and use it as external lib in my android project. Instead I should either, reference the whole library project OR creat a jar file manually, and in the right way. Did I understood it correctly? If yes, then are the instructions for combining a few jars into one jar file from general java tutorials appliable to android environment specificaly? (especialy with the library projects I mentioned) – Lucas Nov 28 '13 at 18:41
  • 2
    "Did I understood it correctly?" -- yes. "If yes, then are the instructions for combining a few jars into one jar..." -- a JAR is a JAR, so it should work fine. If you run into issues, post an SO question where you explain your problems. "especialy with the library projects I mentioned" -- a resource-less Android library project winds up being just a regular Java project, where you happen to compile against `android.jar` rather than something from Java SE. A library project only gets distinctive with stuff like resources, manifest merging, etc. – CommonsWare Nov 28 '13 at 19:13
  • Thanks a lot, I guess that covers it. – Lucas Nov 28 '13 at 23:35

2 Answers2

0

If you are searching for the quickest way to do this, in Eclipse highlight your library project, then go to File > Export and under Java select JAR. From there, you can select a multitude of options, including which other referenced projects should be exported as part of the JAR.

Commonsware is correct, it's just a JAR, there is no magic. If you need a build system option then consider using Ant or Gradle to package the JAR for you. Do not however, try to use what is in the bin folder, as that is not meant for you to use.

stevebot
  • 23,275
  • 29
  • 119
  • 181
-1

You need to make sure you export the library in your Build Path. For Eclipse, you can Right-click on the project, choose "Build Path" > "Configure Build Path", go to the "Order and Export" tab on the right side, and make sure that your library is checked in the list there (it might be contained in one of several library groups if your Project has multiple dependencies).

anddev84
  • 1,473
  • 12
  • 30
  • I assume you mean to do it in my "ProjectB", from above example? If so, I do not have a ProjectA listed there, as it is refferenced by the project, not by external jar (keep in mind). So my "ProjectA's" jar is listed under "Android Dependencies", and those are indeed checked to be exported, but that still does not include the ProjectA's jar inside ProjectB's jar. – Lucas Nov 28 '13 at 08:49