Android include .jar in ant compilation

只愿长相守 提交于 2019-12-22 07:15:07

问题


I try to include in my application compilation a .jar compiled.

I use ant to compile my Android application.

When I add this task to build.xml :

 <javac srcdir="${src}"
     classpath="xyz.jar" />

compilation failed on android package importation :

[javac] Compiling 1 source file
[javac] C:\HelloWorld\src\com\example\hellowolrd\HelloWorld.java:3: package android.app does not exist
[javac] import android.app.Activity;
[javac]                   ^

Whereas when my task was not in build.xml, compilation succeeded.


回答1:


If you're using the standard ant script from android create project then you should be able to dump any jars in a libs directory and have them included automatically (documentation).




回答2:


I just added lib to javac and it did the trick:

ant -lib lib debug



回答3:


If you have a build.xml you have already edited (altered variables, custom imports, etc) and are a little nervous about running generic commands on it, you can also add:

<javac srcdir="libs"
     classpath="xyz.jar" />

to the build.xml file and it will work. It is the manual equivalent of the command

ant -lib lib debug



回答4:


If you're not familiar with how Ant works, it's easier to use Eclipse for your Android projects. Then you can add jars using a GUI. http://developer.android.com/guide/appendix/faq/commontasks.html#addexternallibrary

Also, based on your other question, this appears to be what you are attempting to do: http://developer.android.com/guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject



来源:https://stackoverflow.com/questions/5108026/android-include-jar-in-ant-compilation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!