Android安卓开发-eclipse正确添加第三方jar包
本文轉載自http://www.cnblogs.com/developerY/archive/2013/04/18/3027997.html,在此對原作者表示感謝!
? ? ? ? ? ? ? 首先要說的是為什么會出現這個問題?我們在以往開發java程序的過程中都已經習慣于通過add external archives來添加第三方的jar包,之所以不能在android項目中用同樣的方法引入第三方jar包的原因,下面是來自eclipse j2ee開發者之一 Russ Bateman 的解釋:
? ? ? ? ? ?? ? I'm an Eclipse JEE developer and have been in the habit for many years of adding third-party libraries via the "User Library" mechanism in Build Path. Of course, there are at least 3 ways to add a third-party library, the one I use is the most elegant, in my humble opinion.
This will not work, however, for Android, whose Dalvik "JVM" cannot handle an ordinary Java-compiled class, but must have it converted to a special format. This does not happen when you add a library in the way I'm wont to do it.
Instead, follow the (widely available) instructions for importing the third-party library, then adding it using Build Path (which makes it known to Eclipse for compilation purposes). Here is the step-by-step:
What you've done here accomplishes two things:
他的意思是android的dalvik虛擬機不能直接處理編譯過的java .class文件,因此直接添加第三方jar包需要經過一定的處理才能被android項目正常識別并使用。以下是他提供的步驟:
? ? 4.右鍵點擊項目名,依次選擇Build Path -> Configure Build Path,選擇library選項卡。點擊右邊的add jars,選擇libs目錄下的jar包
? ? ?注:這一步就幫助android虛擬機來處理之前添加的jar包
理論上到這一步應該就可以正常使用了,但是如果到這一步你調試還會出錯的話可以嘗試右鍵點擊libs目錄,選擇build path –> configure as source folder ,基本上到這一步就可以正常使用第三方jar包,繼續你的android開發之旅了
總結
以上是生活随笔為你收集整理的Android安卓开发-eclipse正确添加第三方jar包的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android安卓开发-'Theme.A
- 下一篇: android安卓开发-eclipse平