table of Contents
- How to upgrade Android Gradle Gradle compilation speed or reduce compilation time
- The final optimization
- Problems encountered
- 3. Android Studio is set in the automatic compilation check function was invalid problem?
- 2. Timeline in Gradle Scan report - FROM-CACHE - Build cache result - Unpack takes a long time how to do?
- 1. In accordance with references: Android projects open build scan Gradle's (build-examine) - Jane book step to do, then Sync, an error
- Reference material
How to upgrade Android Gradle Gradle compilation speed or reduce compilation time
The final optimization
Optimization results than
Before optimization: just modify one line of code, click on the "Build - make project" compiler need between 15 to 28 seconds
After optimization: just modify one line of code, click on the "Build - make project" compiled only about 8-10 seconds, if the modified code once compiled, can hit the cache, basic 3 to 4 seconds to compile complete.
Development machine configuration
Infrastructure Operating system Windows 7 6.1 CPU cores 8 cores Max Gradle workers 8 workers Java runtime JetBrains s.r.o OpenJDK Runtime Environment 1.8.0_152-release-1343-b01 Java VM JetBrains s.r.o OpenJDK 64-Bit Server VM 25.152-b01 (mixed mode) Max JVM memory heap size 9544 MB
All project sources, various caching temporary directory are moved to the high-performance SSD disk
- TOSHIBA- TR200 Although the SSD, but obviously not enough high-performance (although it may may be slightly better than the average mechanical point)
gradle.properties Configuration
#因为电脑有20G内存,所以在原来的基础上直接乘与5倍,足够同时打开3个以上项目了。
org.gradle.jvmargs=-Xmx5120m -XX:MaxPermSize=1280m -Dfile.encoding=UTF-8
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.caching=true
#假如不启动会报错: Unable to get provider com.squareup.leakcanary.internal.LeakCanaryFileProvider: java.lang.ClassNotFoundException
android.useAndroidX=true
android.enableJetifier=true
android.enableBuildCache=true
Problems encountered
3. Android Studio is set in the automatic compilation check function was invalid problem?
Reference material
- About IDEA can not time compilation of a temporary solution. . . . - MyHome - OSCHINA
- Automatically compiles the early use of idea - bee's blog - CSDN blog
- Android Studio : auto build like Eclipse - Stack Overflow
- "Make project automatically" - only while not running/debugging – IDEs Support (IntelliJ Platform) | JetBrains
2. Timeline in Gradle Scan report - FROM-CACHE - Build cache result - Unpack takes a long time how to do?
The reason :
Compile caching (Build Cache) directory where the disk IO performance is too low, it is set to high-performance SSD solid state disk can greatly enhance unpack (Unpack) speed (lower unpack time-consuming).
For example :
The same cache size: "Cache artifact 3.62 MB / 4447 entries"
Cache directory on
TOSHIBA- TR200
Disk, unpack (Unpack) took 13.453sSamsun SSD 850 EVO M.2
Disk, unpacked (the Unpack) Processed 1.644s performance than 10-fold
reference:
1. In accordance with references: Android projects open build scan Gradle's (build-examine) - Jane book step to do, then Sync, an error
Gradle sync failed: Could not find com.gradle:build-scan-plugin:1.8.
Searched in the following locations:
Required by:
project : (2 s 761 ms)
solution
Add the following code to the project root directory:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2' }
}
dependencies {
classpath 'com.gradle:build-scan-plugin:2.3'
}
}
apply plugin: com.gradle.scan.plugin.BuildScanPlugin
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service";
termsOfServiceAgree = "yes"
}
详情参考: Gradle Build Scan Plugin User Manual | Gradle Enterprise Docs
Reference material
-
Put
org.gradle.caching=true
in yourgradle.properties
Android project open Gradle's build scan (build-examine) - Jane books
A fine-grained performance profile is available: use the --scan option.
buildscript { dependencies { #下面这句是添加的 classpath 'com.gradle:build-scan-plugin:1.8' } } #下面5行是添加的 apply plugin: 'com.gradle.build-scan' buildScan { licenseAgreementUrl = 'https://gradle.com/terms-of-service' licenseAgree = 'yes' }
Use a clean build a cache to speed up the construction speed | Android Developers
Use Android 2.3.0 and later versions of the plug-in project to build the cache is enabled by default (unless you explicitly disable build a cache).
How does android.enableBuildCache=true functions in new Android Studio 2.2? - Stack Overflow
- Step 0:Ensure that android.dexOptions.preDexLibraries is either not set or set to true;
- Step 1: android.enableBuildCache=true
- Step 2: Build your Android project and check the following locations to see whether the build cache took effect. By default the cache-dir is /.android/build-cache.
Some accelerated Gradle build on personal experience - for programmers Service
-XX = -Xmx5120m org.gradle.jvmargs: MaxPermSize = 2048m -XX: + = UTF-HeapDumpOnOutOfMemoryError -Dfile.encoding. 8
gradlew Clean --info similar to get such information, the information indicating for each task opened and used Parallel thread informationHow to decrease your Gradle build time by 65%? - Keval Patel - Medium
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
gradlew android:assembleDebug --profile --configure-on-demand --daemon
How to speed up compilation Gradle project? - Jane books
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.daemon=true org.gradle.parallel=true android.enableBuildCache=true 另外在Settings-Build,Execution,Deployment-Commond-line Options中设置"--parallel-threads={cpu线程数量}"也有一定作用
[Translation] week when I build Gradle is how to save a 5 hours - Jane book
# Default value: -Xmx10248m -XX:MaxPermSize=256m org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8