Speed up Android project build time in IntelliJ IDEA

前端 未结 4 1861
失恋的感觉
失恋的感觉 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 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.

提交回复
热议问题