Android Robolectric Gradle - java.lang.OutOfMemoryError: PermGen space

I have an android project with robolectric tests, a total of about 2084 test units right now. But I ran into problems adding more tests due to 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 

with strack trace, I get the following

 * 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) ... 

In my `gradle.properties in the root directory and my modules directory, I tried to put the following and nothing worked. I still have a memory problem.

 org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -Xms512m 

I tried the options from Android Studio Gradle Problem: OutOfMemoryError: PermGen space is still out of luck. I also watched sonarRunner java.lang.OutOfMemoryError: PermGen space .

Hope to help you with this. Thanks

+5
source share
2 answers

The information I have collected.

Abdella gave some idea of โ€‹โ€‹the problem, and this is due to the number of generic classes created. "you have a check https://plumbr.eu/outofmemoryerror/permgen-space "

Evgeny Martynov also mentioned a parameter from the robolectric gradle configuration, which I can add. Link to https://github.com/robolectric/robolectric-gradle-plugin#configuration-using-dsl

The main problem with my code is that with the limited PermGen space, I created many Spy objects in Mockito that seem to have eaten most of the space.

+1
source

Try a larger number than 512m: org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -Xms512m

Edit

As @Eugen Martynov mentions, If you use the robolectric gradle plugin , you can specify them as DSL configuration

+8
source

Source: https://habr.com/ru/post/1210200/


All Articles