2013-01-05 38 views
7

類似於this question後,我收到以下錯誤:「GC開銷超限」添加依賴

[INFO] --- android-maven-plugin:3.3.0:dex (default-dex) @ betodef-android --- 
[INFO] /usr/lib/jvm/java-6-sun-1.6.0.32/jre/bin/java [-Xmx1024M, {snip} 
[INFO] 
[INFO] UNEXPECTED TOP-LEVEL ERROR: 
[INFO] java.lang.OutOfMemoryError: GC overhead limit exceeded 

後,我增加了一些依賴性,包括fastutil,我的Android項目發生這種情況。但是,增加可用於dex的內存並不能解決問題。

回答

9

問題在於dex格式的限制,特別是the 65536 limit on the number of method references

診斷問題,增加內存到一個更大的數量(啓用調試/詳細輸出沒有幫助,好奇)。就我而言,我添加了以下到android-maven-plugin配置:

<dex> 
    <jvmArguments> 
     <jvmArgument>-Xmx4096M</jvmArgument> 
    </jvmArguments> 
</dex> 

選擇一個足夠大的堆大小後,信息發生變化,包括像這樣:

[INFO] trouble writing output: Too many methods: 172296; max is 65536. By package: 
[INFO]  20 android.app 
[INFO]  18 android.content 
[INFO]  1 android.content.pm 
[INFO]  7 android.content.res 
[INFO]  7 android.hardware 
[INFO]  38 android.media 
[INFO]  20 android.opengl 
[INFO]  11 android.os 
[INFO]  1 android.text.method 
[INFO]  8 android.util 
[INFO]  38 android.view 
[INFO]  2 android.view.inputmethod 
[INFO]  21 android.widget 
... 
[INFO]  3 com.google.common.annotations 
[INFO] 746 com.google.common.base 
[INFO]  9 com.google.common.base.internal 
[INFO] 833 com.google.common.cache 
[INFO] 8478 com.google.common.collect 
[INFO]  50 com.google.common.eventbus 
[INFO] 385 com.google.common.hash 
[INFO] 597 com.google.common.io 
[INFO]  92 com.google.common.math 
[INFO] 134 com.google.common.net 
[INFO] 521 com.google.common.primitives 
[INFO] 404 com.google.common.reflect 
[INFO] 954 com.google.common.util.concurrent 
[INFO]  16 default 
[INFO] 227 it.unimi.dsi.fastutil 
[INFO] 1370 it.unimi.dsi.fastutil.booleans 
[INFO] 17249 it.unimi.dsi.fastutil.bytes 
[INFO] 17249 it.unimi.dsi.fastutil.chars 
[INFO] 17279 it.unimi.dsi.fastutil.doubles 
[INFO] 17263 it.unimi.dsi.fastutil.floats 
[INFO] 17309 it.unimi.dsi.fastutil.ints 
[INFO] 628 it.unimi.dsi.fastutil.io 
[INFO] 17315 it.unimi.dsi.fastutil.longs 
[INFO] 26514 it.unimi.dsi.fastutil.objects 
[INFO] 17257 it.unimi.dsi.fastutil.shorts 
[INFO]  2 java.awt 
[INFO]  5 java.awt.datatransfer 
[INFO] 206 java.io 
[INFO] 346 java.lang 
[INFO]  10 java.lang.ref 
[INFO]  71 java.lang.reflect 
[INFO]  27 java.math 
[INFO]  26 java.net 
[INFO] 108 java.nio 
[INFO]  6 java.nio.channels 
[INFO]  2 java.nio.charset 
[INFO]  13 java.security 
[INFO]  2 java.text 
[INFO] 382 java.util 
[INFO] 128 java.util.concurrent 
[INFO]  33 java.util.concurrent.atomic 
[INFO]  40 java.util.concurrent.locks 
[INFO]  6 java.util.jar 
[INFO]  6 java.util.logging 
[INFO]  10 java.util.regex 
[INFO]  20 java.util.zip 
[INFO]  26 javax.microedition.khronos.egl 
[INFO] 188 javax.microedition.khronos.opengles 
[INFO]  7 sun.misc 

正如你所看到的,在fastutil類中有大量的參考文獻。

有兩種可能的解決方案這個問題的

  1. 使用的替代品問題的相關性(杜)。
  2. 使用優化程序,如Proguardgeneral AndroidMaven-specific)。
+0

您可以嘗試使用--multi-dex選項。 –

+0

引用此:http://developer.android.com/tools/building/multidex.html – cloudsurfin

相關問題