问题描述
我用我的编译(相当简单,只需5个文件与几百LOC)的命令行应用程序在OSX:
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:
BUILD SUCCESSFUL总时间:
BUILD SUCCESSFULTotal time:
26秒
这是为什么?它需要即使我改一个Java文件中只有一行这么多的时间。其中大部分时间都用在 DEX
阶段(约20秒),这是AFAIK创造的Dalvik字节code。但我的朋友说,也适用于使用Eclipse Windows上的同一个项目说,编译只需要一两秒钟,他的机器上。有什么我可以做,以加快这一proccess?
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 /平台工具目录下,然后重命名 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与你之前选择的名称。这将prePEND(无证)--incremental属性,每一个DEX调用,这将大型减少仅德兴这之间架起已经改变类的构建时间。现在看起来是这样的:
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,5s
0.5秒,而不是20年代是一个巨大的差别!
0.5s instead of 20s is a huge difference!
编辑 - 几句话:
- 您必须使用此之前至少一次编译你的项目,因为它使用previous classes.dex文件
- 您可以用比蚂蚁 其他Android工具链时遇到问题
- you have to compile your project at least once before using this, because it uses previous classes.dex file
- you can run into problems when using other Android toolchains than ant
更新:
谷歌发布的SDK工具21.0,这使得上述的调整absolete,因为它支持pre-德兴。终于来了!
Google released SDK Tools 21.0, which renders above tweak absolete, because it does supports pre-dexing. Finally!
这篇关于在命令行编译Android项目是缓慢的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!