18

I am going to create a library project which has several dependencies (jar files). I am confused because I've seen some android projects which has LIB or LIBS folder under project root folder (together with bin,gen,res,src.etc..)

Even I add LIB or LIBS folder, then put the jar files on it. Still need to set the project properties in order to recognize the added jar files by doing Project Properties => Java Build Path => Libraries tab => Add JARs... button.

I am using Eclipse with Android Plugin. When I add LIBS, it will appear the Android logo on the top of the LIBS folder. It is recognized by the plugin but still need to set it in the project properties (same the above adding JARs)

Which is the correct directory structure for Android Project?

eros
  • 4,946
  • 18
  • 53
  • 78
  • 1
    Traditionally from the Java days, it's lib but some prefer libs. – momo Aug 25 '11 at 05:26
  • added jar files by doing Project Properties => Java Build Path => Libraries tab => Add JARs... do this first eclipse will take care , and u can have both(lib or libs) – Randroid Aug 25 '11 at 05:26

3 Answers3

24

If you use the Android command line to create your project, it'll default to libs/. It turns out that the Android Ant tasks are set to look in libs/ by default.

See $ANDROID_HOME/tools/ant/main_rules.xml:

<property name="jar.libs.dir" value="libs" />

If you just care about Eclipse, you can use whatever you want.

In newer revisions of ADT (revision 17 onwards), the Ant-based build system and the Eclipse plug-in are aligned so that they behave the same way. This means, by default, only the jars that are present in the libs folder are included in the final apk file. These jars would automatically appear under "Android Dependencies" in your Eclipse project.

For more details please refer here. http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

krishnakumarp
  • 8,967
  • 3
  • 49
  • 55
Pete Doyle
  • 937
  • 7
  • 11
  • Yes you're right, i found the above mentioned property in build.xml. Thanks – eros Aug 25 '11 at 07:32
  • Thanks so much for this info. I have an old Android project where I had put a JAR file into a "jars" directory. I started getting "Unable to resolve superclass" errors from dalvikvm (a class in my app was extending a class from the JAR). This went away after moving the JAR to "libs" instead of "jars". – jfritz42 Jan 03 '13 at 18:36
2

It doesn't matter actually. It can be lib or libs. Whether jar files are in lib or in libs, you just need to do right click on project, select "Build path => Add to build path" , thats it.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

Citing: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

If you are still referencing jar libraries manually instead of putting them under libs/ be aware of the following:

  • If the project is a Library project, these jar libraries will not be automatically visible to application projects. You should really move these to libs/
  • If the project is an application, this can work but you must make sure to mark the jar files as exported.
C.d.
  • 9,932
  • 6
  • 41
  • 51