简体   繁体   English

如何将库添加到android项目?

[英]How to add a library to an android project?

I have downloaded a messaging framework library from eneter.net. 我已经从eneter.net下载了消息传递框架库。 In eclipse I have imported the library to the /libs folder. 在eclipse中,我已将库导入到/ libs文件夹。 I right clicked on the library and then added it to the build path. 我右键单击该库,然后将其添加到构建路径。 I know that the code is right, but when I compile it and try to run it, it says that that it can't find the classes. 我知道代码是正确的,但是当我编译并尝试运行它时,它说它找不到类。 Odd thing is when I open up the apk in a zipping program, the library wasn't added to the apk at compile time. 奇怪的是,当我在一个压缩程序中打开apk时,库在编译时并未添加到apk中。 Does anyone know why this would be? 有谁知道为什么会这样吗?

Try right-clicking your project in Eclipse's project explorer, then hit Properties . 尝试在Eclipse的项目资源管理器中右键单击您的项目,然后点击Properties Go to the tab labeled Java Build Path and hit Add Library... (or if it is a jar file, Add JARs... if you already added the Jar to your project and Add External JARs... if it is not yet within the project). 转到标签为Java Build Path的选项卡,然后单击Add Library... (如果它是一个jar文件,则如果已将Jar Add External JARs...到项目中,则Add External JARs... Add JARs...如果尚未将Jar Add External JARs...到项目中,则Add External JARs...在项目中)。 From there, browse for the library you wish to add and add it to the project. 从那里浏览要添加的库,然后将其添加到项目中。 Re-compile (maybe even Project->Clean) and try running it, and see if the library gets added now. 重新编译(甚至是Project-> Clean),然后尝试运行它,看看是否现在添加了库。

I right clicked on the library and then added it to the build path 我右键单击库,然后将其添加到构建路径

That is not necessary, as of the R17 version of the ADT plugin in Eclipse. 从Eclipse中的ADT插件的R17版本开始,这不是必需的。 Moreover, it may cause problems if you do it. 此外,如果这样做可能会引起问题。

Does anyone know why this would be? 有谁知道为什么会这样吗?

Possibly because there is a typo in your directory name, such that it is not named libs/ . 可能是因为您的目录名称中有一个错字,所以它没有命名为libs/ By adding it manually to your build path, you are compiling against it, but the build tools are not adding it to the APK. 通过手动将其添加到构建路径中,您正在针对它进行编译,但是构建工具并未将其添加到APK中。

Is the library in the form of a complete Android project? 该库是否以完整的Android项目形式存在? This is then used with another Android project by going to the Properties of that project, selecting the Android tab, and then finding and selecting that library in the lower window. 然后将其与另一个Android项目一起使用,方法是转到该项目的“属性”,选择“ Android”选项卡,然后在下部窗口中找到并选择该库。

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

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