Android Studio using 100% CPU on an i7 processor for project Rebuild

后端 未结 4 1911
故里飘歌
故里飘歌 2021-02-05 12:19

My Windows 7 machine has a quad core i7 processor. When I Rebuild my project, it takes on average 25 seconds. And when I launch the app, it takes on average 36 seconds (before

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 12:34

    In addition to optimizations specific to Gradle (see below), I recommend that you try disabling anti-virus protection for your Gradle caches directory and your Android Studio project directory. For me, this reduces my build times by roughly 50%. Excluding those same directories from Windows Search indexing can also help.

    Gradle optimizations I use, in ~/.gradle/gradle.properties.

    org.gradle.daemon=true
    org.gradle.jvmargs=-Xmx6144m <-- Tweak this based on available RAM
    org.gradle.caching=true
    org.gradle.parallel=true
    kotlin.incremental=true
    

    Note that enabling caching means you sometimes have to explicitly clear your caches when switching branches. I run this script when I run into puzzling build issues.

    #!/bin/bash
    
    # Clean Android cache
    ./gradlew cleanBuildCache
    
    # Clean Gradle cache, prompting for each directory
    find ~/.gradle/caches -maxdepth 1 -name build-cache* -print -exec rm -rfI {} \;
    
    # Clean Project
    ./gradlew clean
    
    # Stop Gradle Daemon
    ./gradlew --stop
    

提交回复
热议问题