2017-03-06 222 views
1

当用户打开应用程序时,会导致应用程序崩溃的问题是什么?Xamarin.Forms应用程序在Android中崩溃

我HockeyApp整合,显示的错误:

VMRuntime.newNonMovableArray java.lang.OutOfMemoryError: Failed to allocate a 63701004 byte allocation with 16777056 free bytes and 41MB until OOM

Xamarin caused by: java.lang.OutOfMemoryError: Failed to allocate a 63701004 byte 
allocation with 16777056 free bytes and 41MB until OOM 
dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 
android.graphics.BitmapFactory.decodeStreamInternal()BitmapFactory.java:639 
android.graphics.BitmapFactory.decodeStream()BitmapFactory.java:615 
android.graphics.BitmapFactory.decodeStream()BitmapFactory.java:653 

回答 我已经解决了问题

  1. 更新Xamarin.Forms的NuGet。
  2. 删除解决方案中的包文件。
  3. 再次构建解决方案。
+1

的OutOfMemoryError是相当自我解释 – Jason

+0

你能告诉我们发生错误相关的代码? – zett42

+0

@ zett42更新与描述 – tanktaeyang

回答

2

在您的清单中添加这些行android:hardwareAccelerated="false",android:largeHeap="true"它可能会解决您的问题。

<application 
    android:allowBackup="true" 
    android:hardwareAccelerated="false" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:largeHeap="true" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
+0

我已经试过了,应用程序仍然崩溃 – tanktaeyang

0

我有同样的问题。事实证明,多项改变解决了这个问题。

首先,我确保我的应用程序可以用处理大内存堆。这是一个设置,可以设置在应用程序的清单/变化:

<application 
    ... 
    android:largeHeap="true"> <!-- This line does the trick. --> 

其次,我确信,我执行小影像尺寸尽可能。在我的情况下,我决定将最大分辨率限制为720像素或屏幕分辨率,无论是较小的。因此,我调整大图片:

int maxImageSideLength = Math.Min(720, Math.Max(myScreenHeight, myScreenWidth)); 
// see tutorials how to resize the image now 

最后,我保证到哪里分配给图像视图我分配了一个新的图像之前处置图像位图(使用的内存)。我不确定这是否真的有必要,因为我无法相信指定一个新的图像位图没有正确清理,但我将其留在了我的代码中,我仍然对平稳运行的应用程序感到满意。例如:

Bitmap resizedImage = ResizeImage(fileName, maxImageSideLength); 
imageView.SetImageBitmap(null); // this is to free allocated memory 
imageView.SetImageBitmap(resizedImage); 
GC.Collect(); // dispose of the Java side bitmap