如何限制DEX内存使用情况 [英] How to limit DEX memory usage
问题描述
我想设置DEX任务可以在基于gradle这个功能的Android项目中使用的最大内存,但无法找到任何选项来做到这一点。
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屋!