简体   繁体   English

Android,Eclipse,Put .jar in“lib”&“add to build path”vs Put .jar in“libs”

[英]Android, Eclipse, Put .jar in “lib”&“add to build path” vs Put .jar in “libs”

I was trying to add the loopj .jar library into my project, in Eclipse v3.7.2 我试图在Eclipse v3.7.2中将loopj .jar库添加到我的项目中

First I added the .jar into the "lib" directory, right clicked on it and picked "add to build path". 首先,我将.jar添加到“lib”目录中,右键单击它并选择“添加到构建路径”。 It compiles fine but when executing I get an error "Could not find class 'com.loopj.android.http.AsyncHttpClient'. 它编译得很好,但在执行时我得到一个错误“找不到类'com.loopj.android.http.AsyncHttpClient'。

So I remove the .jar from the build path, and move it into the "libs" directory. 所以我从构建路径中删除.jar,并将其移动到“libs”目录中。

No need to add the the build path when it's in the "libs" directory, this time it compiles fine and executes fine too. 当它在“libs”目录中时,不需要添加构建路径,这次它编译得很好并且执行也很好。

So what is the subtile difference between the "lib" directory & "add to build path" vs "libs" directory? 那么“lib”目录和“添加到构建路径”与“libs”目录之间的微妙区别是什么?

So what is the subtile difference between the "lib" directory & "add to build path" vs "libs" directory? 那么“lib”目录和“添加到构建路径”与“libs”目录之间的微妙区别是什么?

Android's current build tools (Eclipse and command-line) expect that JARs are in a libs/ directory. Android的当前构建工具(Eclipse和命令行)期望JAR位于libs/目录中。 It will automatically add those JARs to your compile-time build path. 它会自动将这些JAR添加到编译时构建路径中。 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. 更重要的是,它会将JAR的内容放入您的APK文件中,因此它们将成为您的运行时构建路径的一部分。

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. 手动使用lib/和mucking与您的构建路径将解决编译时问题,但是您的JAR内容不在您的APK中,因此在运行时将无法使用。

Citing: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects 引用: 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: 如果您仍然手动引用jar库而不是将它们放在libs下/请注意以下事项:

  • If the project is a Library project , these jar libraries will not be automatically visible to application projects. 如果项目是库项目应用程序项目将不会自动显示这些jar库。 You should really move these to libs/ 你应该把它们移到libs /
  • If the project is an application , this can work but you must make sure to mark the jar files as exported . 如果项目是一个应用程序 ,这可以工作,但您必须确保将jar文件标记为已导出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM