Android Robolectric Gradle - java.lang.OutOfMemoryError:PermGen空间

laz*_*pig 5 android out-of-memory gradle robolectric

我有一个Android项目设置与robolectric测试,现在总共约2084个单元测试.但是我一直在考虑添加更多测试的问题java.lang.OutOfMemoryError: PermGen space.

objc[11380]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
java.lang.OutOfMemoryError: PermGen space                        
Exception in thread "Test worker" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-0" java.lang.OutOfMemoryError: PermGen space
:app:testDebug FAILED   
Run Code Online (Sandbox Code Playgroud)

随着strack追踪,我得到以下

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:testDebug'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java
...
Caused by: org.gradle.process.internal.ExecException: Process 'Gradle Test Executor 1' finished with non-zero exit value 1
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:365)
    at org.gradle.process.internal.DefaultWorkerProcess.waitForStop(DefaultWorkerProcess.java:161)
    at org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor.stop(ForkingTestClassProcessor.java:86)
    at org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor.endBatch(RestartEveryNTestClassProcessor.java:60)
    at org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor.stop(RestartEveryNTestClassProcessor.java:54)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
...
Run Code Online (Sandbox Code Playgroud)

在我的根目录和我的模块目录中的`gradle.properties中,我尝试了以下内容并且没有任何效果.我仍然遇到了内存不足的问题.

org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -Xms512m
Run Code Online (Sandbox Code Playgroud)

我尝试过Android Studio Gradle问题的选项:OutOfMemoryError:PermGen空间仍然没有运气.我也一直在看sonarRunner java.lang.OutOfMemoryError:PermGen空间.

希望能得到一些帮助.谢谢

Chu*_*ulo 8

尝试超过512米的数字: org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -Xms512m

编辑

正如@Eugen Martynov所提到的如果你使用robolectric gradle插件,你可以将它们指定为DSL 配置

  • robolectric测试是否从gradle继承了这些参数?如果你使用robolectric gradle插件,你可以在`build.gradle`中指定它们.https://github.com/robolectric/robolectric-gradle-plugin#configuration-using-dsl (2认同)

laz*_*pig 1

我收集到的信息。

阿卜杜拉(Abdellah)对这个问题给出了一些见解,这与创建的类总数有关。“您已检查https://plumbr.eu/outofmemoryerror/permgen-space

Eugen Martynov 还提到了我可以添加的 robolectric gradle 插件配置中的参数。链接https://github.com/robolectric/robolectric-gradle-plugin#configuration-using-dsl

我的代码的主要问题是,在 PermGen 空间有限的情况下,我在 Mockito 中创建了很多 Spy 对象,这似乎占用了大部分空间。