Ошибка в памяти: куча памяти Java на Android Studio
Как я могу исправить java.lang.OutOfMemoryError: Java heap space
при компиляции моего проекта Android?
Я получаю это после обновления до версии 1 Android Studio. Но я не думаю, что это проблема. Скорее всего, когда я начну обновлять свое приложение до SDK 21 (до этого был SDK 20). Но я тоже не был так уверен.
Я гугл вокруг какой - то исправить, но не мог найти тот, который работает. Большинство исправлений для Eclipse IDE.
Это полная ошибка logcat, которую я получаю при компиляции:
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)
Это из-за одной библиотеки jar, которую я использовал (zip4j)? Я попытался удалить его, но ошибка OOM все еще происходит. Есть идеи как это исправить?
Редактировать:
Я также отредактировал файл gradlew, чтобы увеличить размер -Xmx.
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\" \"-Xmx2048M \"-XX:MaxPermSize=512M\" \"-XX:ReservedCodeCacheSize=512M\""
Ничего не меняется
Изменить 2:
Также сделал это исправление, но ничего не мог поделать:
Попробуйте следующее:
Ctrl + Alt + S → Компилятор → Gradle
В поле VM Options
напишите:
-Xmx 2048 м-ХХ: MaxPermSize = 512 м
Ответы
Ответ 1
Я, наконец, решил это, ограничив службу Google Play в зависимости от gradle.
Однако проблема была вызвана службой Google Play, и, просто изменив ее на определенную библиотеку, она теперь решена.
com.google.android.gms:play-services-base:6.5.87
UPDATE
Дополнительная информация о андроидах
Ответ 2
Это старый, но просто добавьте его в файл сборки
dexOptions {
javaMaxHeapSize "2g"
}
Ответ 3
У меня была аналогичная проблема на Android Studio 2.3.3. Упаковка APK не сможет сказать Java heap space
при создании из Android Studio и попытке обработать библиотеку .so 300 МБ. В моем случае для его исправления потребовались две вещи. Ваш build.gradle
должен содержать что-то вроде этого:
android {
dexOptions {
javaMaxHeapSize "4G"
}
}
В корне вашего проекта вы должны иметь файл с именем gradle.properties
, содержащий следующее:
# That 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
Ответ 4
Ответы выше для gradle сборок (или общего -Xmx). Если кто-то попадет сюда для проекта gradle, я решил проблему, увеличив максимальный размер кучи DEX в настройках студии Android. > Build, Execution, Deployment = > Compiler = > Android Compilers
Ответ 5
Я использую ОС Windows. Я решил это, обновив _JAVA_OPTIONS до '-Xmx1024m'
- Win + X, выберите SYSTEM
- Выберите "Дополнительные системные настройки"
- Выберите "Переменные среды"
- Создать/изменить переменную с именем "_JAVA_OPTIONS"
- значение переменной обновления как -Xmx1024m
нажмите, чтобы увидеть снимок
Ответ 6
вы изменили неправильные аргументы, вы должны увеличить размер на -XX: MaxPermSize = 512M до -XX: MaxPermSize = 2048M или около того:), потому что эмулятор android использует много оперативной памяти.
Ответ 7
назначить больше памяти Gradle в файле проекта gradle.properties. Например:
org.gradle.jvmargs = -Xmx1024m
Ответ 8
Build => Чистый проект
затем
Build => Перестроить проект
Когда я делаю это, это всегда исправляет для меня.
Ответ 9
Вот что я сделал:
1-й шаг: в вашем приложении перейдите к GRADLE SCRIPTS → GRADLE.PROPERTIES → измените org.gradle.jvmargs = -Xmxm на org.gradle.jvmargs = -Xmx4G
2-й шаг: в вашем приложении перейдите в GRADLE SCRIPTS → build.gradle → в андроиде {
//добавить эту строку:
dexOptions {
javaMaxHeapSize = "4G"
}
}
Ответ 10
Эта проблема также может возникнуть при использовании отладочной сборки Proguard. Чтобы решить эту проблему, отключите minifyEnabled
и shrinkResource
на false.
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
} }