2017-03-06 221 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