Damasia
Damasia

Reputation: 155

android-maven-plugin causes java.lang.OutOfMemoryError when trying to create dex

I need a hand. I'm using android-maven-plugin 3.0.0 and maven-external-dependency-plugin 0.4 in an android project. I'm using these libraries from different repositories as dependencies:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android-test</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency> 
        <groupId>com.admob.android.ads</groupId> 
        <artifactId>admob-android</artifactId> 
        <version>4.0.4</version> 
    </dependency>
    <dependency>
        <groupId>com.google.code</groupId>
        <artifactId>google-api-translate-java</artifactId>
        <version>0.97</version>
    </dependency>
    <dependency>
        <groupId>com.db4o</groupId>
        <artifactId>db4o-core-java5</artifactId>
        <version>${com.db4o.version}</version>
    </dependency>
    <dependency>
        <groupId>com.db4o</groupId>
        <artifactId>db4o-cs-java5</artifactId>
        <version>${com.db4o.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.james</groupId>
        <artifactId>apache-mime4j</artifactId>
        <version>0.6</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.0.1</version>
    </dependency> 
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet</artifactId>
        <version>${restlet.version}</version>
    </dependency>
</dependencies>

Dependencies are all satisfied but when it's time to ingrate all jars into Android dex I get an out of memory error:

[INFO] UNEXPECTED TOP-LEVEL ERROR:
[INFO] java.lang.OutOfMemoryError: Java heap space
[INFO]  at com.android.dx.cf.code.OneLocalsArray.<init>(OneLocalsArray.java:46)
[INFO]  at com.android.dx.cf.code.OneLocalsArray.copy(OneLocalsArray.java:51)
[INFO]  at com.android.dx.cf.code.OneLocalsArray.copy(OneLocalsArray.java:33)
[INFO]  at com.android.dx.cf.code.Frame.copy(Frame.java:98)
[INFO]  at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:683)
[INFO]  at com.android.dx.cf.code.Ropper.doit(Ropper.java:639)
[INFO]  at com.android.dx.cf.code.Ropper.convert(Ropper.java:252)
[INFO]  at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:256)
[INFO]  at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:134)
[INFO]  at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:87)
[INFO]  at com.android.dx.command.dexer.Main.processClass(Main.java:483)
[INFO]  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[INFO]  at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[INFO]  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[INFO]  at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[INFO]  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[INFO]  at com.android.dx.command.dexer.Main.run(Main.java:206)
[INFO]  at com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO]  at com.android.dx.command.Main.main(Main.java:95)

Trying to increase memory adding this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <forkMode>pertest</forkMode>
        <argLine>-Xms1024m -Xmx2048m</argLine>
        <testFailureIgnore>false</testFailureIgnore>
        <skip>false</skip>
    </configuration>
</plugin>

or this:

<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <inherited>true</inherited>
    <configuration>
        <argLine>-Xmx1024m</argLine>

...

or exporting maven_opts like this:

export MAVEN_OPTS=-Xmx1024m

do not solve the problem

I get several warnings about classes in dependent files being compiled with an old class format but I'm not sure that is the source of the problem:

[INFO] warning: Ignoring InnerClasses attribute for an anonymous inner class
[INFO] (org.osgi.framework.AdminPermission$1) that doesn't come with an
[INFO] associated EnclosingMethod attribute. This class was probably produced by a
[INFO] compiler that did not target the modern .class file format. The recommended
[INFO] solution is to recompile the class from source, using an up-to-date compiler
[INFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
[INFO] indicate that it is *not* an inner class.

I would appreciate any help. Here's a full output with debugging turned on from the console so you can take a closer look at the error: http://pastebin.com/5DPBihH0

Best.

Dama

Upvotes: 4

Views: 1287

Answers (2)

dmon
dmon

Reputation: 30168

This was a known issue, but I believe it was fixed in the android-maven-plugin version 3.1.0. The latest is 3.1.1. You didn't post your pom.xml so I can't tell if that's the issue, but it sounds like it is.

If you can't upgrade for some reason, this is the configuration that applies:

  <dex>
    <jvmArguments>
      <jvmArgument>-Xms256m</jvmArgument>
      <jvmArgument>-Xmx512m</jvmArgument>
    </jvmArguments>     
  </dex>

Here's the issue reported on their site: http://code.google.com/p/maven-android-plugin/issues/detail?id=146

And also in the Springsource blog: http://blog.springsource.org/2011/11/07/updated-maven-support-for-android-projects/

Upvotes: 3

pawelzieba
pawelzieba

Reputation: 16082

I think it's connected with those warnings:

[INFO] warning: Ignoring InnerClasses attribute for an anonymous inner class
[INFO] (org.osgi.framework.AdminPermission$1) that doesn't come with an
[INFO] associated EnclosingMethod attribute. This class was probably produced by a
[INFO] compiler that did not target the modern .class file format. The recommended
[INFO] solution is to recompile the class from source, using an up-to-date compiler
[INFO] and without specifying any "-target" type options. The consequence of ignoring
[INFO] this warning is that reflective operations on this class will incorrectly
[INFO] indicate that it is *not* an inner class.

Answers that should help you:

"Ignoring InnerClasses attribute" warning is killing Eclipse
What is the "Ignoring InnerClasses attribute" warning output during compilation?
http://code.google.com/p/maven-android-plugin/issues/detail?id=26

Upvotes: 0

Related Questions