28

I am wondering, if there is any way, how to set skip packaging and dexing in IntelliJ IDEA like in Eclipse and ADT. There is Additional VM Options field in Android DX Compiler section in IntelliJ Preferences, maybe this could be a way, how to set it. I would also appreciate another tips, how to speed up IntelliJ Android project build.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
sealskej
  • 7,281
  • 12
  • 53
  • 64
  • 1
    What is the motivation? IntelliJ doesn't perform dexing and packaging when you run "junit" run configuration. – ekudel Nov 12 '12 at 09:18
  • I am not sure, how should I add "junit" run configuration and If can junit even work with Android. – sealskej Nov 13 '12 at 12:02
  • how does eclipse skip packaging and dexing? when you build an app you have to dex it before you can compile the apk. – toadzky Nov 13 '12 at 22:02
  • @toadzky It only skips during automatic builds, not for export or launch. Pretty much pointless, IMO – Geobits Nov 13 '12 at 22:08
  • ah... i knew it compiles on the fly but it still has to do all the Android specific stuff when you deploy it – toadzky Nov 13 '12 at 22:10
  • Please add more details to your question. Why do you think that it's possible to build and test apps on the device without packaging and dexing? If it's not what you need, then why do you need to disable it and how it would affect your workflow? – CrazyCoder Nov 14 '12 at 05:38
  • I guess `skip packaging and dexing` is possible, because this option is in Eclipse and ADT and it speeds up build. But I would also appreciate another tips, how to speed up IntelliJ Android project build to be same fast as in Eclipse. – sealskej Nov 14 '12 at 09:32
  • 2
    Can you show us some stats for building an apk in IDEA and Eclipse? How much is IDEA slower? `skip packaging and dexing` option makes no sense for IDEA as it doesn't need to compile the code to check for errors. Eclipse uses compiler, IDEA analyzes errors on the fly, it's the major difference making some Eclipse specific options obsolete in IntelliJ IDEA. – CrazyCoder Nov 14 '12 at 09:37
  • Please show content of **idea.properties** and **idea.exe.vmoptions**, it could be found in %idea installation directory%\bin\. I had a similar problem on Eclipse and solved it. Maybe I can help you when you post content of those files. – kord Nov 16 '12 at 13:47
  • See http://stackoverflow.com/questions/12088375/compiling-android-project-from-command-line-is-slow/12156551#12156551 – Alex May 02 '13 at 04:50

4 Answers4

31

I'm using IntelliJ 12. I've won time deploying and running Android apps enabling IntelliJ to "Make project automatically". To enable it, just go to Preferences -> Compiler and check "Make project automatically". In the same window check "Compile independent modules in parallel".

Enabling "Make project automatically" allows you skip "Make" task before an Android application launch. You can remove it in "Run/Debug Configurations", selecting your Android Application and removing "Make" task in "Before launch" section.

Jake Andreu
  • 367
  • 1
  • 6
  • 7
  • 1
    I think this is the solution for the problem the OP was trying to describe. Worked for me on the new Android Studio. Reduced my build times from 2+ minutes to just a few seconds – KingFu May 23 '13 at 08:51
  • This is the right answer to the OP question. Drammatically reduced compilation time for my project. – CrAsHeR Jun 13 '13 at 11:55
  • 1
    "Make project automatically" seems to do nothing as of Android Studio 0.1.8+. Have you got this running on the latest release? – goncalossilva Jul 02 '13 at 08:44
  • 7
    Can anyone confirm that this part of answer works for you? >> "Enabling "Make project automatically" allows you skip "Make" task before an Android application launch." << I switched to "Use external build" and "Make project automatically", but AFAIU if you remove "Make" before deploy, your classes won't get dex-ed at all. And this is what happens to me, old apk (one without changes) gets deployed and launched. Tried both IDEA 12 and 13 EAP. – Oleksandr Yefremov Sep 12 '13 at 09:46
  • 3
    I can confirm that one can't simply remove 'Make' step from run configuration. It looks like old APK is executed and new changes are not reflected. I am on IntelliJ IDEA 13.0.1. – Andrey Chernih Jan 08 '14 at 07:06
  • yup +1 : this is amazing because it totally speedens the build process, but pointless since it doesn't actually dex the changed classes. – KG - Jul 15 '14 at 01:03
11

In Eclipse preferences, the complete name of skip packaging and dexing you are referring is Skip packaging and dexing until export or launch. (Speeds up automatic builds on file save), which is a feature added since ADT 12 in orde to address Eclipse incremental compilation problem (which slow down development on Eclipse), check out the Revisions 12.0.0 (July 2011) and this link for more details, Note that packaging and dexing are fundamental step when you are debugging/running project regardless of which IDE (or non) you use. enter image description here

As CrazyCoder mentioned in his comments, IntelliJ doesn't support Eclipse-like incremental compilation and Problems pane by default, in another word, it doesn't auto compile your project when file changed. So this is really not an issue nor feature in IntelliJ.

Your build process bottleneck probably comes from other place. AFAIK in a medium-sized project, the most time build process spend on is compiling resources (AAPT command, check out build process diagram). Some smart people from xdadevelopers found the bottleneck and create a fix version of AAPT:

http://forum.xda-developers.com/showthread.php?t=1907281

I use it myself and I would say the speed boost is feelable in Eclipse, note that it only boost the AAPT step, not packaging ad dexing. If you use InteliJ, it probably doesn't help much as it needn't compile the project quite often.

yorkw
  • 40,926
  • 10
  • 117
  • 130
11

I don't have a solution, but I have an explanation on why there is a huge compilation time difference between Eclipse and IntelliJ. Because there is. Whenever you depend on external modules or libraries: IntellIJ always DEX'es dependent modules. Eclipse seems to be caching them.

I too had experienced this huge difference in one of my projects. I did some basic timing tests and found that my project which built in 40 seconds in IntellIJ only took 20 in Eclipse. A lot of the time was spent in the process where IntelliJ has the status Executing DEX, so this is how I found this question. I then sought to do a more thorough and reproducible experiment and this is what I found.

Project setup

  • A Hello World project from the New Android Application template in Eclipse.
  • Dependency on the AndEngine Open Source Android Game Engine project*.
  • Eclipse: AndEngine Project defined as "Android Library". Added as Reference under the Android tab and Required Project under the Java Build Path/Projects-tab.
  • IntelliJ: AndEngine defined as "Module". Set as dependency for main module HelloWorld, with the export check box not checked (not that I think it matters).

*) I could have used any module here but this was a good example as it a) is fairly big and b) is an Android module, which means I must link it as a Android project and not only as a JAR as dbm suggest in a post above.

I added logging code in the onCreate method of MainActivity.java (the startup activity of HelloWorld) which also called a method in AndEngine which also logged a line. (I modified the constructor of SoundManager to output a line and called the constructor from MainActivity.java). This allowed me to see when the application was finished deploying and that it also had deployed correctly.

I then did the following changes and timed each of them three times in each IDE:

  • A: Modified only the logging line in the main module
  • A+B: Modified both the logging line in the main module and in the AndEngine module.

I did manual timings with a standard stop watch and then rounded up/down to the nearest second. I did three timings in each case and calculated the arithmetic average.

The results:

Graphs of IntellIJ vs Eclipse compile and deploy time

note: I did not include a separate sub-column for "Executing DEX" in Eclipse because it simply outputs "make" or "refreshing workspace" in the entire build process.

When running from Eclipse, you can see from the numbers that I save time when I only modify the main module - which is as expected. But in IntelliJ the compile time is the same in both cases!

Conclusion:

IntelliJ does a lot of unneccessary DEX'ing. If anyone knows if this is configurable, I think we would solve what I believe is the root cause of the problem.

Nilzor
  • 18,082
  • 22
  • 100
  • 167
  • Note: The IntelliJ results are probably not valid for Android Studio, which uses a different build system. – Nilzor May 16 '13 at 09:11
  • 3
    What you say makes a lot of sense, I am seeing same thing: a *very* slow DEXing phase which was just OK in the same project inside Eclipse. Perhaps you should report this bug to JetBrains, with all these nice graphs and researches :) – dimsuz Nov 20 '13 at 21:23
0

Sometimes when I add large external JARs to my (Eclipse) project it seems to slow down the build process significantly.

I have, however, noticed that instead of adding the jars as usual (Project -> Properties -> Java Build Path -> Libraries -> Add External JARs...) one can add a user library instead (Project -> Properties -> Java Build Path -> Libraries -> Add Library... -> User Library) and add the external JARs to this library instead.

This have so far always solved my large-JARs-build-time-issues. Some smart guys have also explained to me why this is so, but unfortunately I don't really remember the explanation. I have no experience in IntelliJ - I don't know if this is at all applicable in your case, nevertheless, you might get further ideas from here...

dbm
  • 10,376
  • 6
  • 44
  • 56