【问题标题】:dexifying 18.5 MB "android-4.1.1_r1.jar" gives " java.lang.OutOfMemoryError: Java heap space"dexifying 18.5 MB "android-4.1.1_r1.jar" 给出 "java.lang.OutOfMemoryError: Java heap space"
【发布时间】:2013-08-16 09:09:20
【问题描述】:

我正在尝试启动 OSGI 框架并在 Android 上启动一些捆绑包。其中一个包是 18.5 MB jar 的 android API 包。我读到,为了在 android 上启动 bundle,所有的 bundle 都应该首先被 dexified。

所以我尝试使用以下命令对这个“android-4.1.1_r1.jar”进行dexify:

dx --dex --output=classes.dex C:\Users\student\Documents\eclipse\myPlugins\plugins\android-4.1.1_r1.jar 

但我在命令行上收到此错误:

java.lang.OutOfMemoryError: Java heap space

首先:我真的需要对这个文件进行dexify吗? 第二:如果要dexify的话,怎么才能摆脱上面的错误呢?

增加我的堆大小,

我试过了:java -Xmx4g,但我得到了

Invalid maximum heap size: -Xmx4g
The specified size exceeds the maximum representable size.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

然后我尝试了java -Xmx2g,但我得到了

Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

所以我尝试了java -Xmx1gjava -Xmx1100g 然后我得到了:

Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -client       to select the "client" VM
    -server       to select the "server" VM
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument

    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for m
ore details.

在所有情况下,当我尝试对捆绑文件进行 dexify 时,我仍然得到 相同的错误。我该怎么办?我正在使用安装了 4.00 GB(可用 2.96 GB)的 Windows 32 位。

【问题讨论】:

    标签: java android bundle heap-memory dex


    【解决方案1】:

    最大堆大小由许多因素决定,包括:

    • 您运行的是 32 位还是 64 位 JVM。
    • 无论您是在 32 位还是 64 位操作系统上运行。
    • 您使用的是什么操作系统/版本。
    • 您有多少物理内存。
    • 您的系统是否有足够的磁盘空间分配给分页。
    • 您的 Java 应用程序需要多少非堆内存。

    在现代 32 位 Windows(没有 PAE)上,您可能请求的最大值可能是 1.4Gb 到 1.6Gb (reference)。所以-Xmx1g 应该可以工作......除非你有很多其他的东西同时运行。


    所以你是说我上面展示的有效吗?

    没有。

    我是说它应该有效。您收到“使用”消息的事实令人费解。我认为这意味着命令行有其他错误。 (你忘了告诉java要运行什么类吗?)

    我所说的一个推论是,如果您关闭各种其他应用程序(如 IDE、Web 浏览器、电子邮件客户端)以释放内存和/或分页文件空间,它可能会起作用。 (如果您的页面文件严重碎片化,重新启动也可能会有所帮助。)

    如果这没有帮助,那么:

    • 您可以尝试将 JAR 文件拆分为更小的 JAR 文件。
    • 您可以在更大的机器上进行 dexing。
    • 您可以安装 Linux ...这将允许您在相同的硬件上创建更大的 Java 堆。

    【讨论】:

    • 那么你是说我上面展示的内容有效吗?这是来自-Xmx1g 命令行的“好的”响应吗?但如果这是真的,那就没有用了,因为当我 dexify 并且我需要更大的堆时,Out of Memory 错误仍然显示。在这种情况下有没有其他方法可以将它dexify?
    猜你喜欢
    • 2016-04-15
    • 1970-01-01
    • 2012-08-03
    • 2013-05-18
    • 1970-01-01
    • 2018-12-25
    • 2014-06-15
    • 2013-02-25
    相关资源
    最近更新 更多