简体   繁体   English

将不同的外部jar添加到android项目

[英]Adding different external jars to android project

I've already seen similar questions to this on stackoverflow before, but I've been unable to find a solution to my particular problem. 之前我已经在stackoverflow上看到过类似的问题,但是我一直无法找到解决我特定问题的方法。 What I am wanting to do is add multiple external jar files to an android project that I can build either in eclipse or from a command line, and have the jar files bundled into the apk, so that the program will run on a device correctly. 我想做的是将多个外部jar文件添加到我可以在eclipse中或从命令行构建的android项目中,并将jar文件捆绑到apk中,以便程序可以在设备上正确运行。

I am finding that if I simply add all of my external jars to my project by putting them in the .classpath text file, and declaring them for export, then although my program compiles fine, the resulting apk does not contain the jar files, and running it on the device results in a noclassdeffounderror. 我发现,如果我只是将所有外部jar添加到项目中,方法是将它们放入.classpath文本文件中,然后声明要导出,则尽管我的程序可以正常编译,但生成的apk不包含jar文件,并且在设备上运行它会导致noclassdeffounderror。

The solution in the answer to 2694392 wouldn't really work for me, because if I have to put the jar files in the project's own libs directory, then I will end up fighting with how the source control tree is set up... plus, it is rather annoying to have to manually copy jar files into a local folder that I've already tried to say were external in the first place. 2694392的回答中的解决方案对我而言并不是真正的工作,因为如果我必须将jar文件放在项目自己的libs目录中,那么我最终将与如何设置源代码控制树作斗争...加上,不得不手动将jar文件复制到本地文件夹中是一件很烦的事情,我已经尝试将其首先放在外部文件夹中。 Ideally, the build system should copy any external jar files to the places that the runtime expects them to be all by itself. 理想情况下,构建系统应将任何外部jar文件复制到运行时期望它们全部独立的位置。 me. 我。 In reality, it seems like my question is most similar to that of the poster of question 5312478 , but if I must overload the value of jar.libs.dir to refer to where I might keep the jar files, as suggested in the answer to that question, then I cannot easily import different jar files from different directories. 实际上,似乎我的问题与问题5312478的发布者最相似,但是如我的答案所示 ,如果我必须重载jar.libs.dir的值来引用我可能在哪里保存jar文件,这个问题,那么我不能轻易地从不同目录导入不同的jar文件。

I have a general sense that a solution which copies all external jars from their necessary locations to the necessary libs folder as one of the phases before it fully packages up the apk might be adequate, but being something of a novice with ant, I'm not sure exactly what to put in the custom-rules.xml file such that the script itself does not have to know specifically which jars I am wanting to include (ie, they are all listed out in a single property or something) 我普遍认为,将所有外部jar从它们的必要位置复制到必要的libs文件夹作为一种解决方案,在完全打包apk之前的阶段之一可能是适当的,但是作为ant的新手,我是不知道确切要放在custom-rules.xml文件中的内容是什么,这样脚本本身就不必特别知道我要包括哪些jar(即,它们都在单个属性中列出了)

Thank you so much in advance for any assistance you can offer. 非常感谢您提供的任何帮助。

*edit: Although certainly all attempts to be helpful are immensely appreciated, I would encourage people who may be considering answering this question with something similar to what has been answered elsewhere on stackoverflow to briefly reread above why the answers to the similar questions I have mentioned above are not entirely applicable to my question. *编辑:尽管所有尝试提供帮助的尝试都得到了极大的赞赏,但我还是鼓励那些正在考虑以类似于stackoverflow其他地方回答的问题的方式来回答这个问题的人,简要地回顾一下为什么我提到的类似问题的答案以上并不完全适用于我的问题。 Thank you. 谢谢。

Put your jar files under libs folder, Android Developer tools will take of the rest. 将您的jar文件放在libs文件夹下,其余的将由Android Developer工具处理。

Once you put your jar files into libs, clean and build project. 将jar文件放入libs后,清理并构建项目。 You should be able to use your classes in your java program. 您应该能够在Java程序中使用您的类。

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

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