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

前端 未结 28 2286
太阳男子
太阳男子 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

    The accepted answer is for older versions of android studio and most of them works still now. Updating android studio made it a little bit faster. Don't bother to specify heap size as it'll increase automatically with the increase of Xms and Xmx. Here's some modification with the VMoptions

    1. In bin folder there's a studio.vmoptions file to set the environment configuration. In my case this is studio64.vmoptions Add the following lines if they're not added already and save the file. In my case I've 8GB RAM.

      -Xms4096m
      -Xmx4096m
      -XX:MaxPermSize=2048m
      -XX:+CMSClassUnloadingEnabled
      -XX:+CMSPermGenSweepingEnabled 
      -XX:+HeapDumpOnOutOfMemoryError
      -Dfile.encoding=utf-8`
      
    2. Start android studio. Go to File-> Settings-> Build, Execution, Deployment-> Compiler

      • Check compile independent modules in parallel
      • In command-line Options write: --offline
      • Check Make project automatically
      • Check configure on demand

    In case of using mac, at first I couldn't find the vmoptions. Anyway, here's a nice article about how we can change the vmoptions in MAC OSX. Quoting from this article here.

    Open your terminal and put this command to open the vmoptions in MAC OSX:

    open -e /Applications/Android\ Studio.app/Contents/bin/studio.vmoptions
    

提交回复
热议问题