2
votes

I have very tired with getting java lang out of memory exception in xamarin android project. I didn't find what the root cause of getting this exception. In my android properties set up heap size is '1G' but still getting same issue.I am not getting any issue while xamarin ios project set as starting project.So many post's are suggest to these following solutions 1. increase heap size 2.set large hepad size is true in android manifest file, I am fallow those solutions but getting same issue. Here is the error what I am getting. Please suggest any idea of how to fix this issue. enter image description here

3
What's in the Show Details bit? Is it perhaps trying to allocate a bunch of memory for an image? If you are loading a lot of images on Android, that could be your root cause.Ewald
How can we load lot of images in xamarin forms. Is there any alternative solution. In ios it working in nice, only in android getting this type of issue.Deepak
Ok, so the problem IS loading images. It's probably because the images are way to big for Android compared to iOS. Are you using the correct image sizes for each screen size that you need to support?Ewald
I am using image height 100 and width is 130 for android. These sizes are fine for android.Deepak
Kindly show us what's in the Show Details section of the exception.Ewald

3 Answers

1
votes

Just like you did with the PATH stuff in the other thread, add that to the export _JAVA_OPTIONS="-Xmx1g" to the mix, restart Visual Studio and see if that helps.

If you are still running into issues with with the build failing with an OutOfMemoryException you can try upgrading your JDK to use x64 instead of x86. The x64 JDK handles the larger Heap Size better than the x86 JDK.

Another problem is that maybe you have installed two versions of JDK tries to uninstall one and stay with the most current or that supports 64 bits.

0
votes

I ran into this issue building my android project and @G.hakim's suggestion worked perfectly for me. Thanks for that @G.hakim! For those Building in Visual Studio on Mac,

  • Open The MainApplication.cs file in your Droid Folder
  • Add the following line before the public class MainApplication:... declaration

    [Application(HardwareAccelerated = true, LargeHeap = true)]

Thats it! You can also implement the FFImageLoading package, if your app is image heavy.

0
votes

Well, it's kinda simple all you have to do is go to your manifest file under properties of your current project. Then open the AndroidManifest.xml Then add these two lines in your application node

 android:hardwareAccelerated="true" android:largeHeap="true"