Question

I was trying to add the loopj .jar library into my project, in Eclipse v3.7.2

First I added the .jar into the "lib" directory, right clicked on it and picked "add to build path". It compiles fine but when executing I get an error "Could not find class 'com.loopj.android.http.AsyncHttpClient'.

So I remove the .jar from the build path, and move it into the "libs" directory.

No need to add the the build path when it's in the "libs" directory, this time it compiles fine and executes fine too.

So what is the subtile difference between the "lib" directory & "add to build path" vs "libs" directory?

Was it helpful?

Solution

So what is the subtile difference between the "lib" directory & "add to build path" vs "libs" directory?

Android's current build tools (Eclipse and command-line) expect that JARs are in a libs/ directory. It will automatically add those JARs to your compile-time build path. More importantly, it will put the contents of the JARs into your APK file, so they will be part of your run-time build path.

Using lib/ and mucking with your build path manually will solve the compile-time problem, but then your JAR contents are not in your APK and therefore will not be available to you at runtime.

OTHER TIPS

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top