Repository navigation
java.lang.OutOfMemoryError: Consider increasing the value of ${JavaMaximumHeapSize} #1415
Description
Steps to Reproduce
- On Visual Studio for Windows, click File -> New -> Cross-Platform -> Mobile App.
- Select the Master Detail template. Click OK.
- Build and deploy the Android head to the Android emulator.
Expected Behavior
App builds without issue.
Actual Behavior
App fails to build with the following error:
Is there any harm in setting this value to "1G" by default? It seems like if our default project templates are hitting this errors, many users are likely hitting this either at or shortly after a File -> New Project.
Version Information
Microsoft Visual Studio Community 2017
Version 15.6.1
VisualStudio.15.Release/15.6.1+27428.2002
Microsoft .NET Framework
Version 4.7.03053
Installed Version: Community
Visual F# Tools 10.1 for F# 4.1 00369-60000-00001-AA054
Microsoft Visual F# Tools 10.1 for F# 4.1
Application Insights Tools for Visual Studio Package 8.11.10212.1
Application Insights Tools for Visual Studio
ASP.NET and Web Tools 2017 15.0.40214.0
ASP.NET and Web Tools 2017
ASP.NET Core Razor Language Services 1.0
Provides languages services for ASP.NET Core Razor.
ASP.NET Web Frameworks and Tools 2017 5.2.51214.0
For additional information, visit https://www.asp.net/
Azure App Service Tools v3.0.0 15.0.40215.0
Azure App Service Tools v3.0.0
Azure Data Lake Node 1.0
This package contains the Data Lake integration nodes for Server Explorer.
Azure Data Lake Tools for Visual Studio 2.3.3000.0
Microsoft Azure Data Lake Tools for Visual Studio
Azure Functions and Web Jobs Tools 15.0.40215.0
Azure Functions and Web Jobs Tools
Azure Stream Analytics Tools for Visual Studio 2.3.3000.0
Microsoft Azure Stream Analytics Tools for Visual Studio
C# Tools 2.7.0-beta3-62620-07. Commit Hash: e873e69306527a0424e97af2985370556f474019
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Fabric.DiagnosticEvents 1.0
Fabric Diagnostic Events
JavaScript Language Service 2.0
JavaScript Language Service
JavaScript Project System 2.0
JavaScript Project System
JavaScript UWP Project System 2.0
JavaScript UWP Project System
Merq 1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.
Microsoft Azure HDInsight Azure Node 2.3.3000.0
HDInsight Node under Azure Node
Microsoft Azure Hive Query Language Service 2.3.3000.0
Language service for Hive query
Microsoft Azure Service Fabric Tools for Visual Studio 2.0
Microsoft Azure Service Fabric Tools for Visual Studio
Microsoft Azure Stream Analytics Language Service 2.3.3000.0
Language service for Azure Stream Analytics
Microsoft Azure Stream Analytics Node 1.0
Azure Stream Analytics Node under Azure Node
Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.51212.2
Microsoft Continuous Delivery Tools for Visual Studio 0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.
Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package
Mono Debugging for Visual Studio 4.10.3-pre (ebc79bd)
Support for debugging Mono processes with Visual Studio.
NuGet Package Manager 4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
Office Developer Tools for Visual Studio 2017 ENU 15.0.27326.00
Microsoft Office Developer Tools for Visual Studio 2017 ENU
ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info
SQL Server Data Tools 15.1.61801.210
Microsoft SQL Server Data Tools
ToolWindowHostedEditor 1.0
Hosting json editor into a tool window
TypeScript Tools 15.6.20202.3
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 2.7.0-beta3-62620-07. Commit Hash: e873e69306527a0424e97af2985370556f474019
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
Visual Studio Tools for Universal Windows Apps 15.0.27428.01
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
Workflow Manager Tools 1.0 1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.
Xamarin 4.11.0.46 (97bc99e15)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 4.13.4 (aa3c520f8)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin.Android 1.0
Package with Android components for Visual Studio
Xamarin.Android SDK 8.3.99.0 (HEAD/fb2de613e)
Xamarin.Android Reference Assemblies and MSBuild support.
Xamarin.iOS and Xamarin.Mac SDK 11.9.0.252 (7c88610)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Log File
NU1605: Detected package downgrade: Xamarin.Android.Support.Annotations from 27.0.2 to 27.0.2-preview1. Reference the package directly from the project to select a different version.
MasterDetail.Android -> Xamarin.Android.Support.Design 27.0.2-preview1 -> Xamarin.Android.Support.Compat 27.0.2-preview1 -> Xamarin.Android.Arch.Lifecycle.Runtime 1.0.3 -> Xamarin.Android.Support.Annotations (>= 27.0.2)
MasterDetail.Android -> Xamarin.Android.Support.Design 27.0.2-preview1 -> Xamarin.Android.Support.Compat 27.0.2-preview1 -> Xamarin.Android.Support.Annotations (= 27.0.2-preview1)
NU1605: Detected package downgrade: Xamarin.Android.Support.Annotations from 27.0.2 to 27.0.2-preview1. Reference the package directly from the project to select a different version.
MasterDetail.Android -> Xamarin.Android.Support.v7.AppCompat 27.0.2-preview1 -> Xamarin.Android.Support.Compat 27.0.2-preview1 -> Xamarin.Android.Arch.Lifecycle.Runtime 1.0.3 -> Xamarin.Android.Support.Annotations (>= 27.0.2)
MasterDetail.Android -> Xamarin.Android.Support.v7.AppCompat 27.0.2-preview1 -> Xamarin.Android.Support.Compat 27.0.2-preview1 -> Xamarin.Android.Support.Annotations (= 27.0.2-preview1)
NU1605: Detected package downgrade: Xamarin.Android.Support.Annotations from 27.0.2 to 27.0.2-preview1. Reference the package directly from the project to select a different version.
MasterDetail.Android -> Xamarin.Android.Support.v4 27.0.2-preview1 -> Xamarin.Android.Support.Compat 27.0.2-preview1 -> Xamarin.Android.Arch.Lifecycle.Runtime 1.0.3 -> Xamarin.Android.Support.Annotations (>= 27.0.2)
MasterDetail.Android -> Xamarin.Android.Support.v4 27.0.2-preview1 -> Xamarin.Android.Support.Compat 27.0.2-preview1 -> Xamarin.Android.Support.Annotations (= 27.0.2-preview1)
NU1605: Detected package downgrade: Xamarin.Android.Support.Annotations from 27.0.2 to 27.0.2-preview1. Reference the package directly from the project to select a different version.
MasterDetail.Android -> Xamarin.Android.Support.v7.MediaRouter 27.0.2-preview1 -> Xamarin.Android.Support.v7.Palette 27.0.2-preview1 -> Xamarin.Android.Support.Compat 27.0.2-preview1 -> Xamarin.Android.Arch.Lifecycle.Runtime 1.0.3 -> Xamarin.Android.Support.Annotations (>= 27.0.2)
MasterDetail.Android -> Xamarin.Android.Support.v7.MediaRouter 27.0.2-preview1 -> Xamarin.Android.Support.v7.Palette 27.0.2-preview1 -> Xamarin.Android.Support.Compat 27.0.2-preview1 -> Xamarin.Android.Support.Annotations (= 27.0.2-preview1)
1>------ Build started: Project: MasterDetail.Android, Configuration: Debug Any CPU ------
1> MasterDetail.Android -> C:\Users\Pierce\source\repos\MasterDetail\MasterDetail\MasterDetail.Android\bin\Debug\MasterDetail.Android.dll
1>COMPILETODALVIK : UNEXPECTED TOP-LEVEL error :
1> java.lang.OutOfMemoryError: Java heap space
1> at java.util.Arrays.copyOf(Arrays.java:3210)
1> at java.util.Arrays.copyOf(Arrays.java:3181)
1> at java.util.ArrayList.grow(ArrayList.java:265)
1> at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239)
1> at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231)
1> at java.util.ArrayList.add(ArrayList.java:462)
1> at com.android.dx.dex.file.MixedItemSection.add(MixedItemSection.java:181)
1> at com.android.dx.dex.file.StringIdItem.addContents(StringIdItem.java:91)
1> at com.android.dx.dex.file.UniformItemSection.prepare0(UniformItemSection.java:75)
1> at com.android.dx.dex.file.Section.prepare(Section.java:213)
1> at com.android.dx.dex.file.DexFile.toDex0(DexFile.java:509)
1> at com.android.dx.dex.file.DexFile.toDex(DexFile.java:214)
1> at com.android.dx.command.dexer.Main.writeDex(Main.java:864)
1> at com.android.dx.command.dexer.Main.runMonoDex(Main.java:323)
1> at com.android.dx.command.dexer.Main.run(Main.java:277)
1> at com.android.dx.command.dexer.Main.main(Main.java:245)
1> at com.android.dx.command.Main.main(Main.java:106)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2233,3): error XA5213: java.lang.OutOfMemoryError. Consider increasing the value of $(JavaMaximumHeapSize). Java ran out of memory while executing 'java.exe -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\25.0.3\lib\dx.jar" --dex --no-strict --output obj\Debug\android\bin C:\Users\Pierce\source\repos\MasterDetail\MasterDetail\MasterDetail.Android\obj\Debug\android\bin\classes.zip "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.1\mono.android.jar" obj\Debug\lp\1\jl\formsviewgroup.jar obj\Debug\lp\10\jl\arch-lifecycle-common.jar obj\Debug\lp\11\jl\bin\classes.jar obj\Debug\lp\12\jl\bin\classes.jar obj\Debug\lp\14\jl\bin\classes.jar obj\Debug\lp\15\jl\bin\classes.jar obj\Debug\lp\16\jl\bin\classes.jar obj\Debug\lp\17\jl\bin\classes.jar obj\Debug\lp\18\jl\bin\classes.jar obj\Debug\lp\19\jl\bin\classes.jar obj\Debug\lp\20\jl\bin\classes.jar obj\Debug\lp\21\jl\bin\classes.jar obj\Debug\lp\22\jl\bin\classes.jar obj\Debug\lp\23\jl\bin\classes.jar obj\Debug\lp\24\jl\bin\classes.jar obj\Debug\lp\25\jl\bin\classes.jar obj\Debug\lp\26\jl\bin\classes.jar obj\Debug\lp\27\jl\bin\classes.jar obj\Debug\lp\9\jl\arch-core-common.jar'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

Activity
alanjclark commentedon Mar 14, 2018
I am able to reproduce in:
VS2017 15.6.1
XA 8.2.0.15
Same solution opened in vsmac does not present the same issue in:
VS Mac 7.4 Build 1033
XA 8.2.0.15
jonathanpeppers commentedon Mar 15, 2018
I wasn't able to repro this with just a template on my machine, but I do think it is an issue that happens quickly. Almost every Android app I've worked on (on Windows) I've had to set
JavaMaximumHeapSize.Found some java docs on the cmd line switch for
java.exehere under-Xmx. The docs mention a table of default values, which appear to differ per-platform. I suspect Windows is setting a smaller number by default than macOS. I can't imagine this documentation is exactly up-to-date, and it doesn't mention macOS. Other docs I've found don't have this table at all.We could add something like this to
Xamarin.Android.Common.targets:I don't think this would have any negative side effects, as it is the "maximum" heap size.
@jonpryor do you think this is a good idea?
jonpryor commentedon Mar 16, 2018
The only conceivable problem with defaulting to 1GB is that -- at least at one point in time --
java.exeon Windows was a 32-bit process, and by default processes can only access 2GB of memory -- not contiguously! -- and IIRC that could causejava.exeto break:This is in part why we never provided a default value: What value do we provide? If it's too big, things break. If it's too small, things break.
At one point we had kicked around the idea that if
java.exefailed, we'd re-start it with a larger heap size. (Or make the value "based on" something we knew about.) I don't fully remember why this wasn't done; I think in part the issue was that the number of errors to check for is unknowable.jonpryor commentedon Mar 16, 2018
@jonathanpeppers: could you please install a 32-bit JDK 8 on Windows, and see if it errors out with
java -Xmx1Gfor e.g. a "Hello World" Java app? If that works, we should be able to provide a default value of 1G. If it doesn't work... ¯_(ツ)_/¯Perhaps we can probe the "bit-ness" of
java.exeand provide a default for 64-bit apps?jonathanpeppers commentedon Mar 16, 2018
I tried Java hello world, and it seems to work fine with 32-bit JDK:
Also building the template mentioned on the issue seems to work:
I'll start on a PR for this.
[msbuild] default value for JavaMaximumHeapSize
[Xamarin.Android.Build.Tasks] JavaMaximumHeapSize Default (#1436)
[Xamarin.Android.Build.Tasks] JavaMaximumHeapSize Default (#1436)
stmax82 commentedon Apr 13, 2018
I just ran into this problem with an existing and working solution (commited to subversion) after checking it out on a freshly installed new system.
The system is a fresh installation of Win 10 x64 and the latest Visual Studio (15.6.6).
I "solved" the problem by completely uninstalling Java and installing the latest JDK for x64 (jdk-8u161-windows-x64.exe).
So the default setting seems to be fine for JDK 8u161 x64, but Visual Studio seems to have installed something else that causes the above error.
junniornet commentedon May 27, 2020
Logró solucionar el problema??? Me pasa también lo mismo :/