[英]After upgrading to Gradle 5 and Android Plugin 3.3, my build fails with “Metaspace”
This happened when I upgraded to Gradle 5.0 from 4.10.3, and also the Android Gradle Plugin from 3.2.1 to 3.3.0-rc03 (the latter because it's the first version of AGP to officially support Gradle 5). 这种情况发生在我从4.10.3升级到Gradle 5.0,以及从3.2.1升级到3.3.0-rc03的Android Gradle插件时(后者因为它是正式支持Gradle 5的AGP的第一个版本)。
When I attempt to sync my project after this, I get an error. 当我在此之后尝试同步我的项目时,我收到错误。 The error only says: 错误只说:
* What went wrong:
Metaspace
Subsequent builds either also emitted this error, or something even more obscure, like: 后续构建也会发出此错误,或者更加模糊的内容,例如:
* What went wrong:
Could not initialize class com.gradle.scan.a.e.c
There's no obvious solution to this problem. 这个问题没有明显的解决方案。 A search for "gradle metaspace" turns up release notes for Gradle 5 , which themselves only refer to it here: 搜索“gradle metaspace”会显示Gradle 5的发行说明 ,它本身仅在此处引用它:
#7385 - Limit Metaspace used by Gradle #7385 - 限制Gradle使用的元空间
And the issue itself isn't the most helpful. 问题本身并不是最有帮助的。
As we know , Java 8 removed PermGen and replaced it with Metaspace. 众所周知 ,Java 8删除了PermGen并将其替换为Metaspace。 Pre-Gradle 5, no max was set for Metaspace, meaning it could grow without bound (which it would only do in the presence of a memory leak, either from a plugin or Gradle itself). Pre-Gradle 5,没有为Metaspace设置最大值,这意味着它可以无限制地增长(只有在存在内存泄漏的情况下才能生成,无论是来自插件还是Gradle本身)。 With Gradle 5, a maximum limit of 256 MB is now set by default. 使用Gradle 5时,默认情况下现在设置的最大限制为256 MB。 Once the Gradle process hits this limit, the build will fail with Metaspace
as the error. 一旦Gradle进程达到此限制,构建将失败, Metaspace
作为错误。 This limit is set because it is seen as both "large enough" and sane, and also with the explicit idea to discover memory leaks more quickly. 设置此限制是因为它被视为“足够大”和理智,并且还有明确的想法更快地发现内存泄漏。 (Source: I work for Gradle.) (来源:我为Gradle工作。)
This post gives a clue, but doesn't directly answer the question. 这篇文章给出了一个线索,但没有直接回答这个问题。
It turns out that increasing the metaspace limit is simple. 事实证明,增加元空间限制很简单。 Add this to your gradle.properties
: 将其添加到gradle.properties
:
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
Or some other value that makes sense to you. 或者其他一些对你有意义的价值。 512 is simply twice the default. 512只是默认值的两倍。 Obviously this doesn't "fix" the problem, since the problem is a memory leak somewhere. 显然这不会“解决”问题,因为问题是某处的内存泄漏。 But it will help. 但它会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.