2014-12-12 12 views
15

Come risolvere java.lang.OutOfMemoryError: Java heap space durante la compilazione del mio progetto Android?Errore memoria insufficiente: memoria heap Java su Android Studio

Viene visualizzato dopo l'aggiornamento alla versione 1 di Android Studio. Ma, non penso che questo sia il problema. Molto probabilmente quando avvio l'upgrade della mia app all'SDK 21 (prima era l'SDK 20). Ma non ero nemmeno così sicuro.

Ho cercato su google per somefix, ma non sono riuscito a trovarne uno che funzioni. La maggior parte della correzione riguarda Eclipse IDE.

Questo è l'errore logcat completo che ottengo quando si compila:

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

UNEXPECTED TOP-LEVEL ERROR: 
java.lang.OutOfMemoryError: Java heap space 
    at com.android.dx.rop.code.RegisterSpec$ForComparison.toRegisterSpec(RegisterSpec.java:642) 
    at com.android.dx.rop.code.RegisterSpec.intern(RegisterSpec.java:73) 
    at com.android.dx.rop.code.RegisterSpec.make(RegisterSpec.java:90) 
    at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:323) 
    at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:612) 
    at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:412) 
    at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94) 
    at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787) 
    at com.android.dx.cf.code.Ropper.doit(Ropper.java:742) 
    at com.android.dx.cf.code.Ropper.convert(Ropper.java:349) 
    at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:280) 
    at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137) 
    at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93) 
    at com.android.dx.command.dexer.Main.processClass(Main.java:729) 
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673) 
    at com.android.dx.command.dexer.Main.access$300(Main.java:82) 
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602) 
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) 
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) 
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) 
    at com.android.dx.command.dexer.Main.processOne(Main.java:632) 
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505) 
    at com.android.dx.command.dexer.Main.runMultiDex(Main.java:332) 
    at com.android.dx.command.dexer.Main.run(Main.java:243) 
    at com.android.dx.command.dexer.Main.main(Main.java:214) 
    at com.android.dx.command.Main.main(Main.java:106) 

FAILED 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':app:dexDebug'. 
> com.android.ide.common.internal.LoggedErrorException: Failed to run command: 
    C:\Users\piracyde25\android-sdks\build-tools\21.1.1\dx.bat --dex --no-optimize --multi-dex --main-dex-list C:\Users\piracyde25\workspace\Baucar\app\build\intermediates\multi-dex\debug\maindexlist.txt --output C:\Users\piracyde25\workspace\Baucar\app\build\intermediates\dex\debug --input-list=C:\Users\piracyde25\workspace\Baucar\app\build\intermediates\tmp\dex\debug\inputList.txt 
Error Code: 
    3 
Output: 
    warning: Ignoring InnerClasses attribute for an anonymous inner class 
    (net.lingala.zip4j.unzip.Unzip$1) that doesn't come with an 
    associated EnclosingMethod attribute. This class was probably produced by a 
    compiler that did not target the modern .class file format. The recommended 
    solution is to recompile the class from source, using an up-to-date compiler 
    and without specifying any "-target" type options. The consequence of ignoring 
    this warning is that reflective operations on this class will incorrectly 
    indicate that it is *not* an inner class. 
    warning: Ignoring InnerClasses attribute for an anonymous inner class 
    (net.lingala.zip4j.unzip.Unzip$2) that doesn't come with an 
    associated EnclosingMethod attribute. This class was probably produced by a 
    compiler that did not target the modern .class file format. The recommended 
    solution is to recompile the class from source, using an up-to-date compiler 
    and without specifying any "-target" type options. The consequence of ignoring 
    this warning is that reflective operations on this class will incorrectly 
    indicate that it is *not* an inner class. 
    warning: Ignoring InnerClasses attribute for an anonymous inner class 
    (net.lingala.zip4j.util.ArchiveMaintainer$1) that doesn't come with an 
    associated EnclosingMethod attribute. This class was probably produced by a 
    compiler that did not target the modern .class file format. The recommended 
    solution is to recompile the class from source, using an up-to-date compiler 
    and without specifying any "-target" type options. The consequence of ignoring 
    this warning is that reflective operations on this class will incorrectly 
    indicate that it is *not* an inner class. 
    warning: Ignoring InnerClasses attribute for an anonymous inner class 
    (net.lingala.zip4j.util.ArchiveMaintainer$2) that doesn't come with an 
    associated EnclosingMethod attribute. This class was probably produced by a 
    compiler that did not target the modern .class file format. The recommended 
    solution is to recompile the class from source, using an up-to-date compiler 
    and without specifying any "-target" type options. The consequence of ignoring 
    this warning is that reflective operations on this class will incorrectly 
    indicate that it is *not* an inner class. 
    warning: Ignoring InnerClasses attribute for an anonymous inner class 
    (net.lingala.zip4j.zip.ZipEngine$1) that doesn't come with an 
    associated EnclosingMethod attribute. This class was probably produced by a 
    compiler that did not target the modern .class file format. The recommended 
    solution is to recompile the class from source, using an up-to-date compiler 
    and without specifying any "-target" type options. The consequence of ignoring 
    this warning is that reflective operations on this class will incorrectly 
    indicate that it is *not* an inner class. 

    UNEXPECTED TOP-LEVEL ERROR: 
    java.lang.OutOfMemoryError: Java heap space 
     at com.android.dx.rop.code.RegisterSpec$ForComparison.toRegisterSpec(RegisterSpec.java:642) 
     at com.android.dx.rop.code.RegisterSpec.intern(RegisterSpec.java:73) 
     at com.android.dx.rop.code.RegisterSpec.make(RegisterSpec.java:90) 
     at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:323) 
     at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:612) 
     at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:412) 
     at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94) 
     at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787) 
     at com.android.dx.cf.code.Ropper.doit(Ropper.java:742) 
     at com.android.dx.cf.code.Ropper.convert(Ropper.java:349) 
     at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:280) 
     at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137) 
     at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93) 
     at com.android.dx.command.dexer.Main.processClass(Main.java:729) 
     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673) 
     at com.android.dx.command.dexer.Main.access$300(Main.java:82) 
     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602) 
     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) 
     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) 
     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) 
     at com.android.dx.command.dexer.Main.processOne(Main.java:632) 
     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505) 
     at com.android.dx.command.dexer.Main.runMultiDex(Main.java:332) 
     at com.android.dx.command.dexer.Main.run(Main.java:243) 
     at com.android.dx.command.dexer.Main.main(Main.java:214) 
     at com.android.dx.command.Main.main(Main.java:106) 

è a causa di una libreria vaso che ho usato (zip4j)? Ho provato a rimuoverlo, ma l'errore OOM si verifica ancora. Qualche idea su come risolvere questo problema?

Edit:

Inoltre ho modificato il file gradlew per aumentare la dimensione -Xmx.

GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\" \"-Xmx2048M \"-XX:MaxPermSize=512M\" \"-XX:ReservedCodeCacheSize=512M\"" 

Nessuna modifica.

Edit 2:

fatto anche this correzione, ma non poteva fare troppo:

Prova il seguente:

Ctrl + Alt + S -> Compiler -> Gradle

In VM Options campo scrittura:

-Xmx2048m -XX:MaxPermSize=512m

+0

check heap dump ... È inoltre possibile aggiungere Android : largeHeap = "true" – Prachi

+0

@Prachi nulla aiuta. Non riesco nemmeno a compilarlo ed eseguirlo, come suppongo di controllare la discarica dell'heap? – AimanB

+0

Modificato. Aggiunta una correzione che ho fatto nel file gradlew. – AimanB

risposta

6

L'ho finalmente risolto limitando il servizio Google Play in dipendenza gradle.

Il problema tuttavia è stato causato dal servizio Google Play, e semplicemente cambiandolo in una libreria specifica, ora è risolto.

com.google.android.gms:play-services-base:6.5.87 

UPDATE

Maggiori informazioni android guides

0

hai cambiato gli argomenti sbagliati, dovresti aumentare la dimensione su -XX: MaxPermSize = 512M su -XX: MaxPermSize = 2048M circa :) perché l'emulatore Android utilizza molta RAM.

+0

Stesso errore :(Dovrei aggiungere più memoria al maxperm? – AimanB

+0

sì, fallo e guarda cosa succede :) BTW: quanta RAM hai sulla tua macchina? – aurelius

+0

Questo non è corretto, XX: MaxPermSize è usato per memorizzare "i dati necessari alla macchina virtuale per descrivere oggetti che non hanno un'equivalenza a livello di linguaggio Java.Ad esempio, oggetti che descrivono classi e metodi sono memorizzati nella generazione permanente." (http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html) Riesco a malapena a pensare a uno scenario in cui il codice di AimanB e Android Studio richiedono più di 512 MB di RAM per memorizzare le classi (* non * Oggetti) e metodi. Il problema si trova altrove – Kai

24

Questo è vecchio, ma basta aggiungere questo al file di generazione

dexOptions { 
    javaMaxHeapSize "2g" 
} 
+0

Grazie Graeme! I parametri in 'gradle.properties' erano per motivi sconosciuti sempre ignorati. Questo ha aiutato perfettamente! –

+0

Se si utilizza * dx * dalla riga di comando, è necessario passare il flag * -JXmx2g *: 'dx -JXmx2g --dex ...' – sffc

2

Le risposte di cui sopra sono per Gradle costruisce (o il generale -Xmx). Nel caso in cui qualcuno arrivi qui per un progetto non graduale, ho risolto il problema aumentando la dimensione massima dell'heap di DEX nelle impostazioni di android studio => Build, Execution, Deployment => Compiler => Compilatori Android

+0

Ho trovato questa configurazione in File -> Altre impostazioni -> Impostazioni predefinite -> Build, Execution, Deployment -> Compiler -> Compilatori Android – mianlaoshu

0

assegnare più memoria a Gradle nel file gradle.properties del progetto.Ad esempio:

org.gradle.jvmargs=-Xmx1024m

0

sto usando il SO Windows. Ho risolto questo aggiornando _JAVA_OPTIONS a 'Xmx1024m'

  1. Win + X, scegliere SISTEMA
  2. Scegliere 'Impostazioni di sistema avanzate'
  3. Scegliere 'Variabili d'ambiente'
  4. Crea/Modifica una variabile denominata come '' _JAVA_OPTIONS
  5. aggiornamento del valore variabile Xmx1024m

click to see snapshot

+0

Sembra che l'OP abbia già utilizzato -Xmx1024. –

1

Ho avuto un problema simile su Android Studio 2.3.3. L'imballaggio APK non funzionerebbe dicendo Java heap space durante la creazione da Android Studio e tentando di elaborare una libreria .so da 300 MB. Nel mio caso sono state necessarie due cose per risolverlo. Il tuo build.gradle dovrebbe contenere qualcosa di simile:

android { 
    dexOptions { 
     javaMaxHeapSize "4G" 
    } 
} 

Alla base del progetto è necessario disporre di un file chiamato gradle.properties contenente quanto segue:

# That's needed for java to be able the create the APK with our 300MB native library 
# Basically we grant java a 4GB heap. 
org.gradle.jvmargs=-Xmx4608m 
Problemi correlati