如何限制DEX内存使用情况 [英] How to limit DEX memory usage

查看:630
本文介绍了如何限制DEX内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置DEX任务可以在基于gradle这个功能的Andr​​oid项目中使用的最大内存,但无法找到任何选项来做到这一点。

I am trying to set the maximum memory that DEX task can use in a gradle-based Android project, but can't find any option to do that.

我的动机做,这是因为随着 DEX 有时需要我的电脑启动交换,并成为某些分钟(所以我宁愿看到任务完全没有反应这么多内存失败,然后释放一些更多的资源和重试)

My motivation to do this is because as dex sometimes takes so much memory that my computer starts swapping and becomes completely unresponsive for some minutes (so I would rather see the task fail and then free some more resources and retry)

在我的 gradle.properties org.gradle.jvmargs = - Xmx300m这限制了内存使用的摇篮本身,而是摇篮启动时DX它总是使用 -Xmx1024

In my gradle.properties I have org.gradle.jvmargs="-Xmx300m" which limits the memory used by Gradle itself, but when Gradle starts dx it always uses -Xmx1024.

那么,怎样才能让我限制摇篮DX所使用的内存?

So how can I make Gradle limit the memory used by dx?

推荐答案

在您的build.gradle脚本,设置dexOptions.javaMaxHeapSize配置,以任何你需要的值:

In your build.gradle script, set the dexOptions.javaMaxHeapSize configuration to whatever value you need:

android {
//snip
//add this into your existing 'android' block
    dexOptions {
        javaMaxHeapSize "4g"
    }
//snip
}

来源

这篇关于如何限制DEX内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆