I have a multi-project (~10 modules) of which building takes about 20-30 seconds each time. When I press Run in Android Studio, I have to wait every time to rebuild the app,
Just try this first. It is my personal experience.
I had the same problem. What i had done is just permanently disable the antivirus (Mine was Avast Security 2015). Just after disabling the antivirus , thing gone well. the gradle finished successfully. From now within seconds the gradle is finishing ( Only taking 5-10 secs).
Just create a file named gradle.properties in the following directory:
/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)
Add this line to the file:
org.gradle.daemon=true
For me the speed is now equal to Eclipse.
Source: https://www.timroes.de/2013/09/12/speed-up-gradle/
In our specific case, the problem was due to having the retrolambda plugin, which forced all projects and subprojects to recompile everytime we tried to launch our application, even if no code had been altered in our core modules.
Removing retrolamba fixed it for us. Hope it helps someone.
A trivial change (to a resoruce xml) still took 10 minutes.
As @rivare says in his answer, a command line build is mutch faster (took this down to 15 seconds).
Here are some steps to at least make a trivial build fast from the command line for Windows.
Go to your projects root (where the gradlew.bat is):
cd c:\android\MaskActivity
execute the build:
gradlew assembleDebug
uninstall the apk from the phone directly (drag it to uninstall).
When the build is finished, kill the BIG java process using Windows Task Manager.
OR if you have unix tools on your Windows machine:
ps
"pid" 's are shown:
kill -9 <pid>
Now install your apk:
adb -d install C:\Android\MaskActivity\app\build\outputs\apk\app-debug.apk
Searched everywhere for this and finally found a solution that works for us. Enabling parallel builds (On OSX: preferences -> compiler -> gradle -> "Compile independent modules in parallel"
) and enabling 'make project automatically' brought it down from ~1 min to ~20 sec. Thanks to /u/Covalence.
http://www.reddit.com/r/androiddev/comments/1k3nb3/gradle_and_android_studio_way_slower_to_build/
This setup goes really fast for me (about 2 seconds the build)
build.gradle
android {
dexOptions {
incremental true
preDexLibraries = false
jumboMode = false
maxProcessCount 4
javaMaxHeapSize "6g"
}
}
gradle.properties
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx8192M
my PC:
project files
- All located in local HD