简体   繁体   English

Libs文件夹vs构建路径依赖关系(ANDROID)

[英]Libs folder vs build path dependency (ANDROID)

I have some jar libraries on which my app depends. 我有一些我的应用程序依赖的jar库。 When I copy and paste the jars in the project/libs folder, it builds, compiles and executes correctly. 当我将罐子复制并粘贴到project/libs文件夹中时,它会正确构建,编译和执行。

However, if I right click my project -> Build path -> Configure build path -> Libraries tab -> Add external JARs , and add exactly the same jars, it still gives me no error, it allows me to build and compile, but when the app is executed it crashes. 但是,如果我右键单击项目-> Build path -> Configure build path -> Libraries tab -> Add external JARs ,并添加完全相同的jar,它仍然没有错误,它允许我进行构建和编译,但是执行该应用程序时会崩溃。

Why? 为什么?

If you put jars in libs folder it will automatically add those JARs to your compile-time build path. 如果将jars放在libs文件夹中,它将自动将那些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文件中,因此它们将成为您的运行时构建路径的一部分。

Adding jar to build path with lib 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. 手动添加jar以使用lib构建路径将解决编译时问题,但是JAR内容不在APK中,因此在运行时将不可用。

Don't use add external jar this will add as Absolute path instead of this use the relative path by adding jar, with this you must put all the jar files into the libs directory. 不要使用添加外部jar,因为它将添加为绝对路径,而不是通过添加jar使用相对路径,因此必须将所有jar文件放入libs目录。

If you using Add External Jar it will search for that jar file based on Absolute path so on device that path was not find and you getting Force Close. 如果您使用添加外部Jar,它将根据绝对路径搜索该jar文件,因此在找不到该路径的设备上,您将获得强制关闭。

Try with adding same jar file by using Add Jar and Add External Jar option. 尝试使用“添加Jar”和“添加外部Jar”选项添加相同的jar文件。

check the difference here https://stackoverflow.com/a/10679344/760489 在这里检查差异https://stackoverflow.com/a/10679344/760489

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

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