2016年5月24日 星期二

記憶體不足造成 java.exe finished with n on-zero exit value 1

個人感覺出現這個問題, 大部分是ram的原因

在dos命令列, project的根目錄
下gradlew assembleDebug --info命令
可以見到更多原因


All input files are considered out-of-date for increm
ental task ':app:transformClassesWithDexForDebug'.
Allocated dexExecutorService of size 4            
To run dex in process, the Gradle daemon needs a larg
er heap.
It currently has approximately 989 MB.
For faster builds, increase the maximum heap size for
 the Gradle daemon to more than 3072 MB.
To do this set org.gradle.jvmargs=-Xmx3072M in the pr
oject gradle.properties.
For more information see https://docs.gradle.org/curr
ent/userguide/build_environment.html
Dexing out-of-process.                            
Starting process 'command 'C:\Program Files\Java\jdk1
.8.0_91\bin\java.exe''. Working directory: D:\Android
\Studio\docSearcher\app Command: C:\Program Files\Jav
a\jdk1.8.0_91\bin\java.exe -Djava.awt.headless=true -
Xmx2g -Dfile.encoding=UTF-8 -Duser.country=TW -Duser.
language=zh -Duser.variant -cp C:\Users\mayr\Android\
sdk\build-tools\23.0.3\lib\dx.jar com.android.dx.comm
and.Main --dex --verbose --num-threads=4 --multi-dex
--main-dex-list D:\Android\Studio\docSearcher\app\bui
ld\intermediates\multi-dex\debug\maindexlist.txt --ou
tput D:\Android\Studio\docSearcher\app\build\intermed
iates\transforms\dex\debug\folders\1000\1f\main D:\An
droid\Studio\docSearcher\app\build\intermediates\tran
sforms\jarMerging\debug\jars\1\1f\combined.jar

Successfully started process 'command 'C:\Program Fil
es\Java\jdk1.8.0_91\bin\java.exe''
Error occurred during initialization of VM        
Could not reserve enough space for 2097152KB object h
eap
:app:transformClassesWithDexForDebug FAILED      
:app:transformClassesWithDexForDebug (Thread[Daemon w
orker,5,main]) completed. Took 0.218 secs.
           
FAILURE: Build failed with an exception.
           
* What went wrong:
Execution failed for task ':app:transformClassesWithD
exForDebug'.
> com.android.build.api.transform.TransformException:
 com.android.ide.common.process.ProcessException: jav
a.util.concurrent.ExecutionException: com.android.ide
.common.process.ProcessException: org.gradle.process.
internal.ExecException: Process 'command 'C:\Program
Files\Java\jdk1.8.0_91\bin\java.exe'' finished with n
on-zero exit value 1
           
* Try:      
Run with --stacktrace option to get the stack trace.
Run with                                            -
-debug      
option to get more log output.
           
BUILD FAILED
           


上面紅字部分就是原因所在
我在build.gradle為dex保留2G的heapsize:

dexOptions {
    javaMaxHeapSize "2g"}

結果ram 不夠, 所以造成
java.exe finished with n on-zero exit value 1的錯誤

不過奇怪的是, 我用windows 8.1 64bit 卻不會造成此一問題, 觀察工作管理員ram變化的情形
, 發現java.exe 會跑到高達2G左右, 但別的應用ram卻一直減少, 甚至android studio 也只佔幾十mb而已, 所以別的應用程序, 全部都卡死不動, 只有android studio 的compile 在跑而已.(我一共只有4G ram), 但compile的過程非常久, 可能與ram不足有關.

而windows 8.1 32bit 卻直接報告上面的錯誤, 中止compile程序.

本來已為用32bit的系統, 比較省資源, 但直接就退出來, 所以恐怕得重新評估了.

  © Blogger templates Psi by Ourblogtemplates.com 2008

Back to TOP