如何增快 gradle的編譯速度

語言: CN / TW / HK

對於Android開發者來說,Gradle構建效率會伴隨著專案程式碼的增加而降低。那有沒有什麼好的辦法呢?

目前通過實驗,此辦法可以解決掉一部分問題。但我相信這遠遠不夠...  

先來看看是如何提高構建速度的吧!

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
#開啟並行編譯
org.gradle.parallel=true
#守護程序
org.gradle.daemon=true 
#開啟孵化模式
org.gradle.configureondemand=true

經測試,修改 專案下的 gradle.properties檔案即可提升編譯速度

用命令編譯  gradlew assembleRelease 執行效果 

第一次

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 5m 59s
745 actionable tasks: 31 executed, 714 up-to-dated

第二次

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 3m 43s
745 actionable tasks: 6 executed, 739 up-to-date

相比較之下快了1min以上

如果有更好的辦法歡迎交流分享

分享到: