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

前端 未结 28 1927
太阳男子
太阳男子 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 08:46

    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).

    0 讨论(0)
  • 2020-11-22 08:49

    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/

    0 讨论(0)
  • 2020-11-22 08:49

    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.

    0 讨论(0)
  • 2020-11-22 08:49

    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.

    1. Go to your projects root (where the gradlew.bat is):

      cd c:\android\MaskActivity

    2. execute the build:

      gradlew assembleDebug

    3. uninstall the apk from the phone directly (drag it to uninstall).

    4. 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>
    
    1. Now install your apk:

      adb -d install C:\Android\MaskActivity\app\build\outputs\apk\app-debug.apk

    0 讨论(0)
  • 2020-11-22 08:50

    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/

    0 讨论(0)
  • 2020-11-22 08:51

    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:

    • CPU Intel(R) Pentium(R) CPU G2030 @ 3.00GHz, 3000 Mhz, 2 procesadores principales, 2 procesadores lógicos
    • x64
    • Microsoft Windows 7 Professional
    • (RAM) 16,0 GB

    project files
    - All located in local HD

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