Android-maven-plugin raises java.lang.OutOfMemoryError when trying to create dex

I need a hand. I am using android-maven-plugin 3.0.0 and maven-external-dependency-plugin 0.4 in an android project. I use 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> 

The dependencies are all satisfied, but when it's time to infect all the banks in Android dex, I get an error from memory:

 [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 by 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 that:

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

...

or export maven_opts as follows:

 export MAVEN_OPTS=-Xmx1024m 

do not solve the problem

I get some warnings that classes in dependent files are compiled in the format of the old class, but I'm not sure if this 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, the full debugging output is enabled from the console so that you can more carefully consider the error: http://pastebin.com/5DPBihH0

Best.

Dama

+4
source share
2 answers

This was a known issue, but I believe that it was fixed in android-maven-plugin version 3.1.0. The last is 3.1.1. You have not posted your pom.xml , so I can’t say if this is a problem, but it looks like it is.

If you cannot upgrade for any reason, this will be the configuration used:

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

Here the problem is reported on their website: http://code.google.com/p/maven-android-plugin/issues/detail?id=146

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

+3
source

I think this is due to these 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 to help you:

"Ignoring InnerClasses Attribute" Warning Kills Eclipse
What is the "Ignore InnerClasses" attribute to display warnings at compile time?
http://code.google.com/p/maven-android-plugin/issues/detail?id=26

0
source

Source: https://habr.com/ru/post/1395607/


All Articles