:app:dexDebug Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:dexDebug'. > com.android.ide.common.internal.LoggedErrorException: Failed to run command: E:\Program Files\adt-bundle-windows-x86-20140702\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output E:\android\workspace\DialogDemo\app\build\intermediates\dex\debug --input-list=E:\android\workspace\DialogDemo\app\build\intermediates\tmp\dex\debug\inputList.txt Error Code: 1 Output: Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED
Gradle打包的時候經常出現此錯誤,命令--stacktrace
Error occurred during initialization of VM Could not reserve enough space for object heap Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
目前google and 百度查詢有兩種解決方案
1.設置java的
-Xms128m
-Xmx512m
-XX:MaxPermSize=250m
修改這三個參數
2.升級JDK
經過測試2種方案都不行
通過
dx.bat --dex
命令的dx.bat腳本有這樣一句代碼
REM By default, give dx a max heap size of 1 gig and a stack size of 1meg. rem This can be overridden by using "-JXmx..." and "-JXss..." options below.
set defaultXmx=-Xmx1024M set defaultXss=-Xss1m
set defaultXmx=-Xmx1024M
原因就是此處設置的Xmx為1024M,編譯打包APK時java虛擬機內存空間不足,修改為512M即可正常編譯打包了。
set defaultXmx=-Xmx512M