从命令行编译Android项目很慢 [英] Compiling Android project from command line is slow

查看:44
本文介绍了从命令行编译Android项目很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下命令从 OSX 上的命令行编译我的(相当简单,只有 5 个文件和几百个 LOC)应用程序:

I'm compiling my (fairly simple, just 5 files with few hundred LOC) app from command line on OSX using:

蚂蚁调试

它有效.但它运行缓慢:

It works. But it works slowly:

构建成功总时间:

26 秒

这是为什么?即使我只更改一个 java 文件中的一行,也需要很多时间.大部分时间花在 dex 阶段(大约 20 秒),也就是 AFAIK 创建 Dalvik 字节码.但是我的朋友也使用 Eclipse 在 Windows 上的同一个项目上工作,他说在他的机器上编译只需要一两秒钟.我可以做些什么来加快这个过程?

Why is that? It takes this much time even if I change only one line in one java file. Most of this time is spent in dex stage (about 20 seconds), which is AFAIK creating Dalvik bytecode. But my friend that also works on the same project on Windows using Eclipse says that compiling takes only a second or two on his machine. Is there anything I can do to speed up this proccess?

推荐答案

我终于找到了解决方案!这有点黑客,但它有效.

I finally found a solution for this! It's a bit of a hack, but it works.

首先,转到您的 ANDROID-SDK/platform-tools 目录,然后将 dx 应用重命名为其他名称,例如 dextool,最后创建新的 dx 包含内容的文件:

First, go to your ANDROID-SDK/platform-tools directory, then rename dx app to something else, like dextool, and finally create new dx file with contents:

#!/bin/sh
shift
dextool --dex --incremental --no-optimize $@

将dextool"替换为您之前选择的名称.这将为每个 dex 调用添加(未记录的)--incremental 属性,这将大量通过仅对构建之间发生更改的类进行 dexing 来减少构建时间.现在看起来像这样:

Replace "dextool" with the name you chose before. This will prepend (undocumented) --incremental attribute to every dex invocation, which will massively decrease build times by dexing only classes that have changed between builds. Now it looks like this:

[dx] 将 dex A (1 defs/11,3KiB) 与 dex B (359 defs/1253,2KiB) 合并.结果是 359 defs/1519,3KiB.花了 0.5 秒

0.5 秒而不是 20 秒是一个巨大的差异!

0.5s instead of 20s is a huge difference!

编辑 - 一些评论:

  • 在使用这个之前你必须至少编译你的项目一次,因为它使用了以前的 classes.dex 文件
  • 在使用除 ant 之外的其他 Android 工具链时,您可能会遇到问题

更新:

Google 发布了 SDK Tools 21.0,这使得上述调整完全无效,因为它确实支持 pre-dexing.终于!

Google released SDK Tools 21.0, which renders above tweak absolete, because it does supports pre-dexing. Finally!

这篇关于从命令行编译Android项目很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆