33

When I change any .java file and build, the compilation takes 16 seconds. I don't understand why it should be so slow!?

I enabled verbose output for Andoroid.

Window > Preferences > Android > Build output > Verbose.

The result output (Console > Android) is:

[19:46:10] Refreshing resource folders.
[19:46:10] Starting incremental Pre Compiler: Checking resource changes.
[19:46:10] Nothing to pre compile!
[19:46:10] Starting incremental Package build: Checking resource changes.
[19:46:10] ignored resource ...\bin\.\classes.dex
[19:46:10] processing ...\A.class
[19:46:10] processing ...\B.class
    ...
[19:46:21] processing com/google/inject/util/Providers.class...
[19:46:21] processing com/google/inject/util/Types.class...
[19:46:24] Using default debug key to sign package
[19:46:24] Packaging ...\bin\resources.ap_
[19:46:24] Packaging classes.dex
    ...
[19:46:25] Packaging ...\annotations.jar
[19:46:25] Build Success!
[19:46:25] Refreshing resource folders.
[19:46:25] Starting incremental Pre Compiler: Checking resource changes.
[19:46:26] Nothing to pre compile!

The "processing" of .class files took 14 seconds. And it "processed" all files, even from all .jar files linked. I think some thing wrong goes here, as only one .java file was changed.

What can I do to improve the compilation speed?

alex2k8
  • 42,496
  • 57
  • 170
  • 221
  • 1
    What size is your APK ending up as? If its big then it will take Eclipse time to compile it even if you only change one file. – Donal Rafferty May 21 '10 at 16:53
  • 1
    BTW, it does not make sense for me that bigger project should be longer to compile... If A depends on B, and I change A, why to recompile B? I guess ("processing" in log stands for compile). I agree, packaging can be longer, but compilation theoretically should not depend on the size of the project when I change just one file. – alex2k8 May 21 '10 at 18:21
  • My target SDK was at level 4 (Android 1.6) and I was fine. I first started noticing this problem when I switched to level 10 (Android 2.3.3), so as to include features released in that version. I have now switched back to level 4 because the slowness was too much to bear (though I still compile my release apps in Ant at level 10). I tried levels between 4 and 10 that were available, to see where this was introduced, and it appears it started at level 8 (Android 2.2), so before level 8, the compilation speed is fine, on level 8 or later, you may have to optimize eclipse in other ways. – ubzack Jan 30 '12 at 20:19

6 Answers6

55

I think there's a misunderstanding here. As you say, only the modified classes are recompiled (by Eclipse in a matter of milliseconds); after that, however, the ADT plugin takes every compiled class and translates it into Dalvik's bytecode format via the dx tool. The output of this process is a single file, classes.dex, which contains all the classes in your application, including the ones coming from referenced libraries. This last "translation" step is the one that takes longer because it's really poorly optimized: the ADT plugin doesn't cache anything, it just retranslates every class at every build (and it's painfully slow). For medium to big projects this gets really frustrating... I hope Google will improve that in a future ADT/SDK release.

lencinhaus
  • 3,185
  • 1
  • 26
  • 17
  • 7
    On a side note you can disable automatic build in "Project" -> "Build Automatically". Then it will only fully build during application launch, so it will not slow down the Eclipse UI while you work on the code every time you save a file. – jmbouffard Sep 02 '11 at 15:24
  • 4
    the problem with disabling "Build Automatically", is i don't get updated values from resources. which leaves alot of room for mistakes and makes auto-complition useless.. then when you finally build it, you have errors, and have to re-build it again, so it's not saving much time – Vlad Aug 25 '12 at 13:47
  • 2
    Keep build automatically but disable the post compiler (in the preferences under Android > Build). This was you disable only the dexing phase. It'll be done on demand when you launch only. – Xavier Ducrohet Dec 01 '12 at 18:52
  • I find it useful to disable automatic builds, and when I change a resource, to press ctrl-B. To start a build. – Knossos Mar 11 '15 at 11:53
9

One other workaround is:

  • disable the Android Package Builder (right-click on project#Properties#Builders)
  • use ant for build and deployment of apk

see android-workaround-for-slow-building-workspace-problem-in-eclipse for details

oae
  • 1,513
  • 1
  • 17
  • 23
  • It's no effect obviously if you know ant, ant call android build.xml, no performance optimization at all – Trinea Apr 15 '14 at 10:23
4

ADT 21 pre-dex all libraries. This means regular compilation only re-dex the output of your project (faster) and then merges the result with the pre-dexed libraries (pretty quick).

Xavier Ducrohet
  • 28,383
  • 5
  • 88
  • 64
  • Hi Xav, are you aware [this AAPT bottleneck](http://forum.xda-developers.com/showthread.php?t=1907281) and what is your opinion on it? – yorkw Dec 12 '12 at 02:48
  • 2
    Yes. this was submitted through AOSP, then merged internally. It'll be part of the next aapt update. – Xavier Ducrohet Dec 13 '12 at 19:21
  • Cool, then I don't need rename/copy the file from third party anymore:) – yorkw Dec 13 '12 at 21:18
0

Increasing the memory available for Eclipse seems to help a lot. Try launching it like:

eclipse -vmargs -Xms1024m -Xmx2048m
iceheart
  • 49
  • 1
  • 3
0

As alex2k8 mentioned I enabled verbose output. The culprit was AdMob jar file.

I'm using ADT 22.0. My application includes AdMob and during the running or debugging step, the class files in admob jar are converted to dex files which was really slow.

I removed the admob code and the jar from my project temporarily and the build process is normal again.

Vysakh Prem
  • 93
  • 1
  • 12
0

Every time you save, Eclipse package and dexing all files. But this is not necessary because you don't need to deploy your app in apk each time you save.

Anyway, the key of this problem is to uncheck the option:

"Skip packaging and dexing until export or launch. (Speeds up automatic builds on file save.)"

Inside of "Window --> Preferences --> Android --> Build"

This will fix your problem.

Cheers

Marco Hernaiz
  • 5,830
  • 3
  • 27
  • 27