1
如果我從AndroidStudio運行我的Robolectric單元測試,一切都很好,我所有的測試都通過了。如果我嘗試從命令行運行它們,則「./gradlew clean test」會出現OutOfMemoryError錯誤。從Gradle運行Robolectric測試給出OutOfMemoryError。從AndroidStudio精細
我試着在項目的根目錄中編輯gradle.properties文件,但是這似乎沒有效果。我甚至將內存限制設置爲8g,但仍然存在內存不足錯誤,所以我不認爲文件有任何影響。
項目 - > gradle.properties
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# https://stackoverflow.com/questions/17012619/android-studio-gradle-issue-outofmemoryerror-permgen-space
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
堆棧跟蹤
objc[18543]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_72.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_72.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
com.foo.android.ui.MapControllerFragmentTest > testSomething FAILED
java.lang.NoClassDefFoundError at MapControllerFragmentTest.java:92
Caused by: java.lang.ClassNotFoundException at MapControllerFragmentTest.java:92
com.foo.android.ui.MapFragmentTest > testGoogleMapListenersRemovedOnDestroy FAILED
java.lang.OutOfMemoryError
com.foo.android.ui.MapFragmentTest > testLifecyclesPassedToMapView FAILED
java.lang.NoClassDefFoundError at MapFragmentTest.java:37
Unexpected exception thrown.
java.lang.OutOfMemoryError: PermGen space
at sun.misc.Unsafe.defineClass(Native Method)
at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:396)
at java.security.AccessController.doPrivileged(Native Method)
at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:395)
at sun.reflect.MethodAccessorGenerator.generateSerializationConstructor(MethodAccessorGenerator.java:113)
at sun.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:331)
at java.io.ObjectStreamClass.getSerializableConstructor(ObjectStreamClass.java:1376)
我曾嘗試answers from other threads沒有成功。它只涉及活動或片段時拋出錯誤。
任何時候你提到一個異常是拋出,發佈堆棧跟蹤。 –
你有jdk7嗎?我認爲AS已經包含了JDK8。你能升級你的JDK嗎? –
謝謝。這實際上修復了內存錯誤。我只剩下java.lang.ClassNotFoundException。 1錯誤優於2 – whizzle