简体   繁体   English

升级到Gradle 5和Android插件3.3之后,我的构建失败了“Metaspace”

[英]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.

相关问题 升级到Android Gradle Plugin 3.2后,Gradle构建中的Findbugs失败 - Findbugs in Gradle build fails after upgrading to Android Gradle Plugin 3.2 升级到Android插件3.0后,Gradle构建失败 - Gradle build fails after upgrading to Android plugin 3.0 错误:找不到 com.android.tools.build:gradle:3.3。 升级 splunk:mint-android-sdk 的 gradle 版本后引发问题 - Error:Could not find com.android.tools.build:gradle:3.3. Issue raise after upgrading gradle version for splunk:mint-android-sdk 升级到Gradle 3.3和Android构建工具2.3.0时收到构建错误 - Receiving a build error when upgrading to gradle 3.3 and android build tools 2.3.0 gradle 插件更新后,Android Studio 无法构建我的应用程序 - Android studio unable to build my app after gradle plugin updated 升级到最新的 Android Gradle 插件 AndoidX 后出现 Gradle 错误 - Gradle error after upgrading to AndoidX the latest Android Gradle Plugin 升级到Cordova Android 8.0后,Gradle无法同步 - Gradle fails to sync after upgrading to Cordova Android 8.0 升级到Android Gradle插件3.4.0后,类别不再变得模糊 - Class no longer obfuscated after upgrading to Android Gradle plugin 3.4.0 升级到Android Gradle 2.2.0插件后,使用Dagger 2进行Espresso测试中的ClassCastException - ClassCastException in Espresso test with Dagger 2 after upgrading to Android Gradle 2.2.0 plugin 将 android gradle 插件从 4.2.1 升级到 7.0.1 后出现错误 - After upgrading android gradle plugin from 4.2.1 to 7.0.1 getting error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM