kapt 发生异常:java.lang.OutOfMemoryError: GC 开销限制超出
Posted
技术标签:
【中文标题】kapt 发生异常:java.lang.OutOfMemoryError: GC 开销限制超出【英文标题】:kapt An exception occurred: java.lang.OutOfMemoryError: GC overhead limit exceeded 【发布时间】:2019-03-09 12:52:15 【问题描述】:我在构建代码时遇到了这个问题,我遇到了这个异常。我尝试增加 build.gradle 和 Manifest 文件中的堆空间,但它们似乎都没有工作。我也更改了 gradle 属性,但效果不佳。
我认为问题在于我正在使用数据绑定和空间,并且在为相同的文件生成文件时,它碰巧给出了这个异常。
e: [kapt] An exception occurred: java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.google.googlejavaformat.Doc$State.withColumn(Doc.java:81)
at com.google.googlejavaformat.Doc$Token.computeBreaks(Doc.java:486)
at com.google.googlejavaformat.Doc$Level.computeSplit(Doc.java:330)
at com.google.googlejavaformat.Doc$Level.computeBreakAndSplit(Doc.java:320)
at com.google.googlejavaformat.Doc$Level.computeBroken(Doc.java:296)
at com.google.googlejavaformat.Doc$Level.computeBreaks(Doc.java:266)
at com.google.googlejavaformat.Doc$Level.computeSplit(Doc.java:330)
at com.google.googlejavaformat.Doc$Level.computeBreakAndSplit(Doc.java:320)
at com.google.googlejavaformat.Doc$Level.computeBroken(Doc.java:290)
at com.google.googlejavaformat.Doc$Level.computeBreaks(Doc.java:266)
at com.google.googlejavaformat.Doc$Level.computeSplit(Doc.java:330)
at com.google.googlejavaformat.Doc$Level.computeBreakAndSplit(Doc.java:320)
at com.google.googlejavaformat.Doc$Level.computeBroken(Doc.java:296)
at com.google.googlejavaformat.Doc$Level.computeBreaks(Doc.java:266)
at com.google.googlejavaformat.Doc$Level.computeSplit(Doc.java:330)
at com.google.googlejavaformat.Doc$Level.computeBreakAndSplit(Doc.java:320)
at com.google.googlejavaformat.Doc$Level.computeBroken(Doc.java:290)
at com.google.googlejavaformat.Doc$Level.computeBreaks(Doc.java:266)
at com.google.googlejavaformat.Doc$Level.computeSplit(Doc.java:330)
at com.google.googlejavaformat.Doc$Level.computeBreakAndSplit(Doc.java:320)
at com.google.googlejavaformat.Doc$Level.computeBroken(Doc.java:296)
at com.google.googlejavaformat.Doc$Level.computeBreaks(Doc.java:266)
at com.google.googlejavaformat.Doc$Level.computeSplit(Doc.java:330)
at com.google.googlejavaformat.Doc$Level.computeBreakAndSplit(Doc.java:320)
at com.google.googlejavaformat.Doc$Level.computeBroken(Doc.java:290)
at com.google.googlejavaformat.Doc$Level.computeBreaks(Doc.java:266)
at com.google.googlejavaformat.Doc$Level.computeSplit(Doc.java:330)
at com.google.googlejavaformat.Doc$Level.computeBreakAndSplit(Doc.java:320)
at com.google.googlejavaformat.Doc$Level.computeBroken(Doc.java:296)
at com.google.googlejavaformat.Doc$Level.computeBreaks(Doc.java:266)
at com.google.googlejavaformat.java.Formatter.format(Formatter.java:181)
at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:245)
:app:kaptDebugKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or - -debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5m 7s
【问题讨论】:
你能在你的问题中添加例外吗? 请检查可编辑问题。 【参考方案1】:以下 gradle 设置对我有用。
-Xms256m -Xmx4096m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=225m -XX:+UseCompressedOops
这在你的 settings.gradle 文件中作为 org.gradle.jvargs 参数的值,例如
org.gradle.jvmargs=-Xms2560m -Xmx4096m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=225m -XX:+UseCompressedOops
放线
org.gradle.jvmargs=-Xms2560m -Xmx4096m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=225m -XX:+UseCompressedOops
到您的 gradle.properties(项目属性)
【讨论】:
所以 jvargs 设置应该放在 settings.gradle 和 grale.properties 中??【参考方案2】:为特定作业设置堆大小的另一种方法是为每个作业使用环境变量。这样可以确保在不使用需要更高内存的作业时内存可用。
GRADLE_OPTS="-Dorg.gradle.jvmargs=-Xms1024M -Xmx8192M -XX:PermSize=512M -XX:MaxPermSize=2048 -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
JAVA_OPTS="-XX:MaxPermSize=2048M"
【讨论】:
以上是关于kapt 发生异常:java.lang.OutOfMemoryError: GC 开销限制超出的主要内容,如果未能解决你的问题,请参考以下文章