4

I'm developing a software layer that I would like to reuse several time for building my Android applications. Basically I want that, once installed, the software layer any other apps can use it (like a system library).

I was wondering what is the best solution for doing this, when I found that recently Android supports library projects (http://developer.android.com/guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject).

So I decided to create my software layer as a library project, making the code it contains re-usable by the other applications I want to realize.

My software layer depends on a set of external jar, which are correctly located in the lib folder of the library project.

The problem is that when I create a new project referencing the library project I'm not able to see the classes defined into the external jars of the library project: i.e. it seems that they are not part of the classpath.

So when referring to a library project is possible to re-use only the source code defined there? If my library project have some other libraries I have to import these libraries also in the other ones (I want to avoid this!)?

I'm also interested to know if there are other ways for doing this, but searching around I haven't found other ways for realizing Android libraries/shared code.

Thanks.

2 Answers2

3

Android library projects definitely incorporate any JARs you have in the library project's libs/ directory. However, if you are using Eclipse, you probably have to somehow manually add those to your build path of the host project (the one reusing the library).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hello, thanks for your reply. Yes I'm using Eclipse. If I follow what you suggested, what happens when I deploy the host project on the device (the one reusing the library)? I think the jars in the lib folder of the host project will be deployed as well. Don't you think so? – the_dark_destructor Mar 14 '11 at 17:23
  • I think it is _lib/_, not _libs/_ – Audrius Mar 14 '11 at 17:24
  • @the_dark_destructor: "Don't you think so?" -- beats me. I avoid Eclipse to the greatest extent possible. – CommonsWare Mar 14 '11 at 18:08
  • @CommonsWare: what do you use ? – tacone Mar 14 '11 at 18:53
  • @CommonsWare I'm trying right now, I'll let you know what is the result... however I'm sorry that you don't like Eclipse, I'm using it almost for everything (Java, Android, Web-Services, Tex editor..) and I'm quite happy with it, give to it another chance :) – the_dark_destructor Mar 14 '11 at 19:56
  • @tacone: I use an ordinary editor (Komodo Edit, presently) and the command line. – CommonsWare Mar 14 '11 at 20:34
  • @the_dark_destructor: I teach Android application development and watch my students struggle with Eclipse. It does not fill me with warm fuzzies. That being said, it is unavoidable for certain things (e.g., MAT plugin for examining heap dumps), and at least nowadays I have hardware capable of running it (quad core with 4GB of RAM). – CommonsWare Mar 14 '11 at 20:36
  • @CommonsWare @Tacone @Audrius I've managed to understand this issue. CommonsWare was right there is no way to make the host projects see the jars defined in the library project without adding them to their classpaths (weird! that should be one of the advantages of using a library project!). Looking better at the official docs I have understood that even if you use a library project the shared source are included in the host project at deployment-time: so library projects are just a way to not duplicate sources, but the shared source are always deployed with the apk of the host projects(weird!) – the_dark_destructor Mar 14 '11 at 21:52
2

Ok I finally figured out that for solving this is sufficient to add the jars to the host project build-path (no need to re-import them, you can just choose the path from the library project). However it is weird that they are not automatically exported in the host project classpath.