A friend of mine asked me why Android Studio builds so slowly, but you can see the problem by looking at the build log.
Look at the build log first
The log content is as follows:
To run dex in process, the Gradle daemon needs a larger heap. It currently has approximately 910 MB. For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB. To do this set org.gradle.jvmargs=-Xmx2048M In the project gradle. Properties. For more information see docs.gradle.org/current/use…
To run gradle faster, you need to set the memory of gradle to more than 2048M
When you open it, you see
In the gradle home directory, or in the project home directory. We will first optimize in the Project directory
Enter the configuration
org.gradle.jvmargs=-Xmx3062m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true
Copy the code
Specific meaning
- org.gradle.jvmargs: JVM memory management, which exists on the heap. Gradle memory management -- -xMS: The initial allocation of memory is specified by -xms, heap memory. - -xmx: Specifies the maximum memory allocated by -xmx. - -xx :PermSiz:JVM uses -xx :PermSize to set the initial value of non-heap memory - -xx :MaxPermSize to set the maximum size of non-heap memory - org.gradle.daemon=true - org.gradle.parallel=trueCopy the code
That’s it, of course, but Android Studio itself can also be optimized:
Open the Android Studio directory
Configuration is as follows
-Xms512m
-Xmx2048m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-da
-Djna.nosys=true
-Djna.boot.library.path=
-Djna.debug_load=true
-Djna.debug_load.jna=true
-Dsun.io.useCanonCaches=false
-Djava.NET.preferIPv4Stack=true
-XX:+HeapDumpOnOutOfMemoryError
– Didea. Paths. The selector = AndroidStudio2.1
-Didea.platform.prefix=AndroidStudio
Can’t wait to rebootAndroidStudio, try faster compilation.