【问题标题】:"GC Overhead limit exceeded" after adding a dependency添加依赖项后“超出 GC 开销限制”
【发布时间】:2013-01-05 16:36:42
【问题描述】:

this question类似,我收到以下错误:

[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

这发生在我向我的 Android 项目添加了几个依赖项(包括 fastutil)之后。但是,增加dex 的可用内存并不能解决问题。

【问题讨论】:

    标签: android dex


    【解决方案1】:

    问题在于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. 使用有问题的依赖项的替代方法 (duh)。
    2. 使用优化器,例如 Proguard (general Android, Maven-specific)。

    【讨论】:

    猜你喜欢
    • 2011-05-21
    • 2017-12-27
    • 2013-07-13
    • 2018-03-29
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多