如何使用 Ant 编译并 jar 一个 Android 项目?

发布于 2025-01-08 09:46:27 字数 467 浏览 1 评论 0原文

我正在尝试处理整个“Ant”构建系统的事情。我使用以下命令创建了 Android 原生提供的 build.xml: android update project -p .

虽然这给了我一个模板 build.xml 文件,但我想要更多选项。具体来说,我希望能够JAR和/或编译我的项目;最好有版本号。

额外问题:如何从 JAR 构建中排除文件。例如,我有一个用于测试功能的活动,但我不希望将其包含在最终的 JAR 中。

Android 给我的 build.xml 文件是 Gisted 这里,因为它很长(主要是注释)。

编辑:我也在使用 IntelliJ,所以请不要提供 Eclipse 的详细信息!

I'm trying to get a handle on this whole "Ant" buildsystem thing. I've created a build.xml that Android natively gives me by using the command: android update project -p . .

While this has given me a template build.xml file, I would like a couple more options. Specifically, I would like to be able to JAR and/or Compile my project; preferably with a version number.

Bonus Question: How can I exclude files from my JAR build. For example, I have one activity that I've used to test my functionality, but I don't want that to be included in the final JAR.

My build.xml file that Android has given me is Gisted here since it's pretty long (mostly comments).

EDIT: I'm also using IntelliJ so no Eclipse specifics, please!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2025-01-15 09:46:27

具体来说,我希望能够 JAR 和/或编译我的项目;最好有版本号。

在 Android 中,版本号适用于应用程序,而不是 JAR。

话虽这么说,添加 jar 目标只需将其添加到 build.xml 文件的底部即可:

<target name="jar" depends="debug">
    <jar
        destfile="bin/whatever-you-want-to-call-the.jar"
        basedir="bin/classes"
    />
</target>

然后,运行 ant jar编译并打包 JAR 文件。

您将在 我的 GitHub 区域 中的大多数可重用 Android 组件中看到这种模式(请参阅 cwac-< /code> 存储库)。

额外问题:如何从 JAR 构建中排除文件。例如,我有一个用于测试功能的活动,但我不希望将其包含在最终的 JAR 中。

使用 excludesexcludesfile,如 jar Ant 任务文档

Specifically, I would like to be able to JAR and/or Compile my project; preferably with a version number.

In Android, version numbers are for apps, not JARs.

That being said, adding a jar target is a matter of adding this to your build.xml file towards the bottom:

<target name="jar" depends="debug">
    <jar
        destfile="bin/whatever-you-want-to-call-the.jar"
        basedir="bin/classes"
    />
</target>

Then, run ant jar to compile and package the JAR file.

You will see this pattern in most of the reusable Android components in my GitHub area (see the cwac- repos).

Bonus Question: How can I exclude files from my JAR build. For example, I have one activity that I've used to test my functionality, but I don't want that to be included in the final JAR.

Use excludes or excludesfile, as described in the jar Ant task documentation.

孤单情人 2025-01-15 09:46:27

为了重用 Android 和非 Android 项目,我建议您查看 Android Maven 插件。它利用 Maven 的依赖管理和其他强大功能,并且更适合您想要做的事情。

查看网页和文档,也许还有关于Maven 中的 Android 开发:完整参考 我写的目的是为了了解更多信息理解并且有东西可看关于马文。

Android 插件支持普通 jar 工件的重用,如果代码中有 Android 依赖项,您可以使用 apklib 项目。许多项目(如 Roboguice、robolectric、actionbarsherlock 等)都成功地使用了此功能。

For reuse of Android and non-android projects I would suggest you take a look at the Android Maven Plugin. It takes advantage of dependency management and other powerful features of Maven and will be much more suitable to what you want to do.

Checkout the webpage and documentation on it and maybe the chapter about Android development in Maven : The Complete Reference I wrote to get a bit more understanding as well as have something to look at about Maven.

The Android plugin supports reuse for normal jar artifacts and if there are Android dependencies within the code you can use apklib projects. Lots of projects like Roboguice, robolectric, actionbarsherlock and others use this feature successfully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文