IntelliJ Idea giving java.lang.OutOfMemoryError:即使在增加堆大小后,Java堆空间错误

2022-09-02 20:03:21

我在IntelliJ Idea上编译我的Android项目时反复遇到错误。java.lang.OutOfMemoryError: Java heap space

我通过点击这里的链接增加了我的java堆空间,但这并没有解决问题。有趣的是,有时我的应用程序会编译,而在其他时候,由于java堆空间错误,应用程序将无法编译。即使我没有对应用程序进行任何更改,它有时也会编译,有时会失败。

关于我如何解决这个问题的任何想法?

我正在编译一个Android项目,这可能是由于我拥有大量资源(可绘制的hdpi,xhdpi,xxhdpi,large-hdpi,large-xhdpi,large-xxhdpi)吗?但话又说回来,就像我说的,它有时会编译,有时不会编译。我每次都尝试大约10次编译,幸运的是它会成功一次。

这是错误:

内部错误: (java.lang.OutOfMemoryError) Java heap space java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2271) at com.intellij.util.io.UnsyncByteArrayOutputStream.write(UnsyncByteArrayOutputStream.java:52) at com.intellij.util.io.DataOutputStream.write(DataOutputStream.java:34) at java.io.FilterOutputStream.write(FilterOutputStream.java:97) at com.intellij.util.io.IOUtil.writeString(IOUtil.java:63) atorg.jetbrains.jps.incremental.storage.OneToManyPathsMapping$PathCollectionExternalizer.save(OneToManyPathsMapping.java:87) at org.jetbrains.jps.incremental.storage.OneToManyPathsMapping$PathCollectionExternalizer.save(OneToManyPathsMapping.java:84) at org.jetbrains.jps.incremental.storage.AbstractStateStorage$1.append(AbstractStateStorage.java:103) at com.intellij.util.io.PersistentHashMap.doAppendData(PersistentHashMap.java:371) atcom.intellij.util.io.PersistentHashMap.appendData(PersistentHashMap.java:358) at org.jetbrains.jps.incremental.storage.AbstractStateStorage.appendData(AbstractStateStorage.java:101) at org.jetbrains.jps.incremental.storage.OneToManyPathsMapping.appendData(OneToManyPathsMapping.java:50) at org.jetbrains.jps.incremental.storage.SourceToOutputMappingImpl.appendOutput(SourceToOutputMappingImpl.java:50) atorg.jetbrains.jps.builders.impl.BuildOutputConsumerImpl.registerOutputFile(BuildOutputConsumerImpl.java:65) at org.jetbrains.jps.android.AndroidResourceCachingBuilder.runPngCachingbuilder(AndroidResourceCachingBuilder.java:126) at org.jetbrains.jps.android.AndroidResourceCachingBuilder.build(AndroidResourceCachingBuilder.java:48) at org.jetbrains.jps.android.AndroidResourceCachingBuilder.build(AndroidResourceCachingBuilder.java:32) atorg.jetbrains.jps.incremental.BuildOperations.buildTarget(BuildOperations.java:100) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:744) at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:770) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:702) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:523) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:314) at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:179) at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:129) at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:220) at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:112) at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:132) at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166)

提前致谢!


答案 1

转到“设置”(Mac上的首选项)->编译器->Java编译器->最大堆大小(MB)并增加大小,然后重新启动IntelliJ


答案 2

我今天刚刚遇到了这个问题,在File/Settings/Compiler/Java Compiler和.../Compiler/Android Compiler下将堆大小增加一倍/两倍之后,它仍然无法编译。

最终解决我的问题的值是增加称为编译器进程堆大小的值(我将其加倍,但可能不是必需的),可以在文件/设置/编译器下找到

这为我解决了使用Intellij版本12.1.5(现在是最新的)的问题

我也意识到这个线程有点旧...


推荐