Speed up Android project build time in IntelliJ IDEA

前端 未结 4 1702
失恋的感觉
失恋的感觉 2020-12-08 07:37

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

相关标签:
4条回答
  • 2020-12-08 07:45

    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...

    0 讨论(0)
  • 2020-12-08 08:02

    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.

    0 讨论(0)
  • 2020-12-08 08:06

    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.

    0 讨论(0)
  • 2020-12-08 08:08

    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.

    0 讨论(0)
提交回复
热议问题