Building and running app via Gradle and Android Studio is slower than via Eclipse

前端 未结 28 1930
太阳男子
太阳男子 2020-11-22 08:21

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,

相关标签:
28条回答
  • 2020-11-22 09:00

    Update After Android Studio 2.3

    All answers are great, and I encourage to use those methods with this one to improve build speed.

    After release of android 2.2 on September 2016, Android released experimental build cache feature to speed up gradle build performance, which is now official from Android Studio 2.3 Canary. (Official Release note)

    It introduces a new build cache feature, which is enable by default, can speed up build times (including full builds, incremental builds, and instant run) by storing and reusing files/directories that were created in previous builds of the same or different Android project.

    How to use:

    Add following line in your gradle.properties file

    android.enableBuildCache = true
    # Set to true or false to enable or disable the build cache. If this parameter is not set, the build cache is enable by default.
    

    Clean the cache:

    • There is a new Gradle task called cleanBuildCache for you to more easily clean the build cache. You can use it by typing the following in your terminal:

      ./gradlew cleanBuildCache

    • OR You can clean the cache for Android studio 2.2 by deleting all the files store at location

      C:\Users\<username>\.android\build-cache

    0 讨论(0)
  • 2020-11-22 09:00

    Please follow the following steps.

    1. Enable offline mode : Please check below print screen.

      https://i.stack.imgur.com/RF9uG.png

    2. Enable Instant Run : Please check below print screen.

      https://i.stack.imgur.com/mvHKJ.png

      If you want to learn more about instant run please visit android developer site.

    0 讨论(0)
  • 2020-11-22 09:00

    According to the android documentation, add this in the gradle file of app module.

    android {
        ...
        dexOptions {
        preDexLibraries true
        maxProcessCount 8
        }
    }
    
    0 讨论(0)
  • 2020-11-22 09:01

    Here's what helped this beginning Android programmer (former professional programmer, years ago) in speeding up Android Studio 2.2. I know this is a rehash, but, just summarizing in one place.

    Initial builds can still be brutally slow, but restarts of running apps are now usually very tolerable. I'm using a sub-optimal PC: AMD Quad-Core A8-7410 CPU, 8MB RAM, non-SSD HD, Win 10. (And, this is my first Stack Overflow posting.... ;)

    IN SETTINGS -> GRADLE:

    yes for "Offline work" (this is perhaps the most import setting).

    IN SETTINGS -> COMPILER:

    yes for "Compile independent modules in parallel" (not sure if this does in fact help utilize multicore CPUs).

    IN GRADLE SCRIPTS, "build.gradle (Module: app)":

    defaultConfig {
        ...
       // keep min high so that restarted apps can be hotswapped...obviously, this is hugely faster.
       minSdkVersion 14
       ...
        // enabling multidex support...does make big difference for me.
        multiDexEnabled true
    

    ALSO IN GRADLE SCRIPTS, "gradle.properties (Project Properties)":

    org.gradle.jvmargs=-Xmx3048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

    org.gradle.parallel=true org.gradle.daemon=true

    Additionally, testing on a physical device instead of the emulator is working well for me; a small tablet that stands up is convenient.

    0 讨论(0)
  • 2020-11-22 09:03

    If anyone is working a project which is synced via Subversion and this still happening, I think this can slow the process of workflow in Android Studio. For example if it work very slow while: scrolling in a class,xml etc, while my app is still running on my device.

    • Go to Version Control at Preferences, and set from Subversion to None.
    0 讨论(0)
  • 2020-11-22 09:03

    I was fed up with the slow build of android on my local machine. The way I solved this was spinning up a high-end machine on AWS and rsyncing the code from my local to the machine and compiling it over there.

    I saw an immediate increase in the performance and my local system was saved from CPU hog. Check out this tool I created to help the developers speed up their terminal https://stormyapp.com

    0 讨论(0)
提交回复
热议问题