Skip to content

Latest commit

 

History

History
91 lines (67 loc) · 4.27 KB

AndroidStudio提高Build速度.md

File metadata and controls

91 lines (67 loc) · 4.27 KB

AndroidStudio提高Build速度

Android Studio自动发布以来,凭借其强大的功能,很快让开发者都投入到它的阵营下。但是也问题,就是Build速度太慢了。

之前也根据网上的资料,修改了一些配置,但是一次二分多种有时候还是让人抓狂。今天索性记录一下。首先看一下Google+关于该问题的讨论。

  • 使用daemonparallel模式

    在下面的目录中创建一个名为gradle.properties的文件:

    • /home/<username>/.gradle/ (Linux)
    • /Users/<username>/.gradle/ (Mac)
    • C:\Users\<username>\.gradle (Windows)

    文件的内容为:

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

    经过上面的这一步修改是对所有工程都有效果的,如果你只想对某一个工程配置的话,那就在该工程目录下的gralde.properties中进行配置。

    # Project-wide Gradle settings.
    
    # IDE (e.g. Android Studio) users:
    # Gradle settings configured through the IDE *will override*
    # any settings specified in this file.
    
    # For more details on how to configure your build environment visit
    # http://www.gradle.org/docs/current/userguide/build_environment.html
    
    # Specifies the JVM arguments used for the daemon process.
    # The setting is particularly useful for tweaking memory settings.
    # Default value: -Xmx10248m -XX:MaxPermSize=256m
    # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    
    # When configured, Gradle will run in incubating parallel mode.
    # This option should only be used with decoupled projects. More details, visit
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    # org.gradle.parallel=true
    

    打开时默认如上。我们给加添加上面的配置就好。

    当然你也可以通过Studio的设置中进行修改。
    image

  • 使用offline模式

    下一步就是开始offline模式,因为我们经常会在gradle中使用一下依赖库时用+这样的话就能保证你的依赖库是最新的版本,但是这样在每次build的时候都会去检查是不是最新的版本,所以就会耗时。
    image

    在开发过程中是不建议使用动态版本的,在Studio中使用动态版本的gradle中间中使用ALT+ENTER键进行修复。 image image 详细有关为什么不要使用动态版本的介绍,请参考Don't use dynamic versions for your dependencies

  • 增加内存使用SSD
    首先是增大内存, Mac中在Applications中找到Sutio然后右键显示包内容Contents/bin/studio.vmoptions。 打开该文件后修改就可以了,我是的是:

    #
    # *DO NOT* modify this file directly. If there is a value that you would like to override,
    # please add it to your user specific configuration file.
    #
    # See http://tools.android.com/tech-docs/configuration
    #
    -Xms1024m
    -Xmx4096m
    -XX:MaxPermSize=768m
    -XX:ReservedCodeCacheSize=768m
    -XX:+UseCompressedOops
    

    我没看见DO NOT的提示- -!

    • Xms 是JVN启动起始时的堆内存,堆内存是分配给对象的内容。
    • Xmx 是能使用的最大堆内存。
  • 使用Instant Run

    Instantt Run放在这里说可能不合适,但是用他确实能大大的减少运行时间。
    如果还不了解的话可以参考Instant Run
    image