如何使用 ant 构建带有外部库的 android 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2465285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to build an android app with external libraries using ant?
提问by emmby
I have an existing project that builds fine using my IDE. I'd like to use the "android update" command to generate an ant buildfile for this project.
我有一个使用我的 IDE 构建良好的现有项目。我想使用“ android update”命令为这个项目生成一个 ant 构建文件。
The buildfile is generated fine, but the build fails because it's not building with some jarfiles I have in my libs directory.
构建文件生成正常,但构建失败,因为它没有使用我的 libs 目录中的一些 jarfile 构建。
I'd like to figure out the proper way to tell ant to build with some external jar files in my libs directory. How should I do this? Is it a property in build.properties? Do I need to modify build.xml somehow? Or is there a different solution entirely?
我想找出告诉 ant 在我的 libs 目录中使用一些外部 jar 文件构建的正确方法。我该怎么做?它是 build.properties 中的属性吗?我需要以某种方式修改 build.xml 吗?或者是否有完全不同的解决方案?
回答by CommonsWare
but the build fails because it's not building with some jarfiles I have in my libs directory.
但是构建失败,因为它没有使用我的 libs 目录中的一些 jarfile 构建。
And your error message is...what? I suspect you may be misinterpreting the error message.
你的错误信息是……什么?我怀疑您可能误解了错误消息。
I'd like to figure out the proper way to tell ant to build with some external jar files in my libs directory. How should I do this?
我想找出告诉 ant 在我的 libs 目录中使用一些外部 jar 文件构建的正确方法。我该怎么做?
Just put them in libs/
, as Ant will add everything in there to your build path. See this project, and this project, and this projectfor examples.
只需将它们放入libs/
,因为 Ant 会将其中的所有内容添加到您的构建路径中。有关示例,请参阅此项目、此项目和此项目。
回答by akitaben
I spent some time trying to get the Facebook API to work with ant. The trick for me was to add this to my default.properties files.
我花了一些时间试图让 Facebook API 与 ant 一起工作。我的诀窍是将它添加到我的 default.properties 文件中。
android.library.reference.1=../Facebook
Where ../Facebook contains AndroidManifest.xml, etc. The real key being the relative path. Don't use an absolute path because Ant seems to treat your project directory as the root.
其中 ../Facebook 包含 AndroidManifest.xml 等。真正的关键是相对路径。不要使用绝对路径,因为 Ant 似乎将您的项目目录视为根目录。
This should hold true for other library projects that you are including from source code.
这应该适用于您从源代码中包含的其他库项目。
回答by petrsyn
I was dealing with similar issue. I'm building Android project on Jenkins using standard Ant build.xml (generated by Android SDK). I also have reference to another Java project with some shared domain classes. In Eclipse there is no problem with it. The domain project is a project reference. However on Jenkins this domain.jar is built by Maven and it was not accessible by Android project.
我正在处理类似的问题。我正在使用标准 Ant build.xml(由 Android SDK 生成)在 Jenkins 上构建 Android 项目。我还参考了另一个带有一些共享域类的 Java 项目。在 Eclipse 中没有问题。域项目是一个项目引用。但是在 Jenkins 上,这个 domain.jar 是由 Maven 构建的,Android 项目无法访问它。
I have finally solved it by adding this at the end of build.xml:
我终于通过在 build.xml 的末尾添加这个来解决它:
<target name="-pre-build">
<copy todir="${jar.libs.dir}">
<fileset
dir="../path-to-another-project/target"
includes="*.jar" />
</copy>
</target>
This copies all jars from the target directory of another project into "libs" directory of my Android project. The -pre-build Ant target is automatically called before Android compilation starts.
这会将另一个项目的目标目录中的所有 jar 复制到我的 Android 项目的“libs”目录中。-pre-build Ant 目标会在 Android 编译开始之前自动调用。
回答by Alex Volovoy
I agree with Mark, however, if you're planning to modify your build script further - than you need to make it custom. Bring tasks from android/platforms/android-PLATFORMVERSION/templates/android_rules.xml to your build.xml and modify whatever you want to modify. Including location for external libs.
但是,我同意 Mark 的观点,如果您打算进一步修改您的构建脚本 - 而不是您需要对其进行自定义。将 android/platforms/android-PLATFORMVERSION/templates/android_rules.xml 中的任务带到您的 build.xml 并修改您想要修改的任何内容。包括外部库的位置。