如何使用 Ant 构建 Android 项目? (IntelliJ IDE)

发布于 2024-10-17 02:36:27 字数 348 浏览 8 评论 0原文

我在 IntelliJ IDEA IDE 中有一个项目,我想设置一个并行的生产 Ant 构建流程,并且可以随着时间的推移进行扩展。

我已经使用 IntelliJ 的功能创建了一个 Ant 构建文件,它位于“构建”菜单上,因此 Ant 构建过程正在运行,并且在 IDE 中工作。一切都好。

但是 IntelliJ 创建的 Ant 脚本仅编译为类文件,并没有对 APK 执行完整的 Android 构建过程(据我所知)。

您能否向我指出参考源(或示例)来帮助我了解如何使用 ANT 脚本来完整构建 Android 项目?

如果您知道,了解如何扩展它以包括 Proguard、生产签名和插入生产 Maps 密钥也会很有用:)

I've a project in the IntelliJ IDEA IDE and I want to set up a parallel, production Ant build process that I can extend over time.

I have used IntelliJ's feature to create an Ant build file, and it is on the Build menu, so the Ant build process is running, and working within the IDE. All good.

But the Ant script IntelliJ has created is only compiling to class files, and is not doing a full Android build process through to an APK (as far as I can tell).

Can you point me towards a reference source (or an example) to help me understand how to get an ANT script doing a full build of an Android project?

If you know, would also be v useful to know how to then extend it to include Proguard, production signing, and inserting the production Maps key :)

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

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

发布评论

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

评论(2

好听的两个字的网名 2024-10-24 02:36:27

以此为起点:

http://developer.android.com/guide/ development/other-ide.html

我不了解 IntelliJ,但我应该不难创建一个包含您需要的最常用命令的 ant 文件。

更新:

运行以下命令:

android create project --target 8 --name "MyFirstProject" --path /path/to/project --activity StartingActivity  --package net.sample.package

这将创建一个项目结构。这包括一个 build.xml 文件,其中包含构建项目的目标。

要构建应用程序,请在根文件夹 (/path/to/project/) 中运行:

ant debug

它应该编译您的应用程序。

您可能必须安装或配置 ant 才能正常工作,但您应该能够自己弄清楚! :)

(所有信息都在我之前发布的链接中)

Use this as a starting point:

http://developer.android.com/guide/developing/other-ide.html

I don't know IntelliJ but I shoudn't be very hard to create an ant file with the most frequent commands you need.

UPDATE:

run the following command:

android create project --target 8 --name "MyFirstProject" --path /path/to/project --activity StartingActivity  --package net.sample.package

This will create a project structure. This includes a build.xml file that contains targets to build the project.

To build the application, in the root folder (/path/to/project/) run:

ant debug

It should compile your application.

You may have to install or configure ant before this works correctly but you should be able to figure it out by yourself! :)

(All the info is in the link I posted earlier)

丿*梦醉红颜 2024-10-24 02:36:27

SDK 文档中对此进行了很好的描述。只需 3 个步骤即可使其发挥作用:

  1. 假设您已经使用 IntelliJ Idea 等功能强大的工具开发您的活动一段时间了。因此,正如 Ollie 在评论中提到的那样,您不必从头开始创建 Android 项目。在命令行中运行:

    android更新项目--path“项目路径”--target“android-X”

    其中 X 是 API 级别

  2. 在第一步之后自动创建 build.xml。现在打开 IntelliJ,转到 ant 构建面板并添加该 build.xml。

  3. 重要的步骤是打开创建的任务的属性并在执行选项卡的命令行中添加调试或发布。

现在您可以运行目标并享受结果。需要付出更多的努力才能编译成签名版本。

注意:您现有的项目结构应与 android 项目匹配。请查看文档。例如,我将外部库放入“lib”子文件夹中,并且仅在将“lib”重命名为“libs”后才使其正常工作

It's pretty well described in SDK documentation. Just 3 steps to make it work:

  1. Assuming you have been developing your activity for a while with such powerful thing as IntelliJ Idea. So as Ollie mentioned in comment you don't have to create android project from scratch. Run in command line:

    android update project --path "Path to your project" --target "android-X"

    where X is API level

  2. After step one build.xml was created automatically. Now you open IntelliJ, go to ant build panel and add that build.xml.

  3. The important step is to open properties of created task and add debug OR release to command line at execution tab.

Now you can run target and enjoy the result. It will take some more efforts to compile into signed release.

Note: your existing project structure should match to android project. Please review documentation. E.g. I had external library put in "lib" subfolder and I managed it to work only after renaming "lib" to "libs"

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