Compiling Android project from command line is slow
android, compilation, dex, performance
Solution
I finally found a solution for this! It's a bit of a hack, but it works.
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 $@
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] Merged dex A (1 defs/11,3KiB) with dex B (359 defs/1253,2KiB). Result is 359 defs/1519,3KiB. Took 0,5s`
0.5s instead of 20s is a huge difference!
Edit - few remarks:
- 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
UPDATE:
Google released SDK Tools 21.0, which renders above tweak absolete, because it does supports pre-dexing. Finally!
Problem
I'm compiling my (fairly simple, just 5 files with few hundred LOC) app from command line on OSX using: `ant debug` It works. But it works slowly: `BUILD SUCCESSFUL Total time:` `26 seconds` 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?