Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: java.lang.OutOfMemoryError #821

Open
ghnp5 opened this issue Aug 25, 2023 · 8 comments
Open

Build: java.lang.OutOfMemoryError #821

ghnp5 opened this issue Aug 25, 2023 · 8 comments

Comments

@ghnp5
Copy link

ghnp5 commented Aug 25, 2023

Describe the bug

Hi.

I'm looking to rebuild the TWA app I have, but I'm getting this every time:

cli ERROR Command failed: gradlew.bat assembleRelease --stacktrace

FAILURE: Build failed with an exception.

* What went wrong:
java.lang.OutOfMemoryError (no error message)

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
java.lang.OutOfMemoryError
        at com.google.common.io.ByteStreams.copy(ByteStreams.java:108)
        at org.gradle.api.internal.changedetection.state.RuntimeClasspathResourceHasher.hash(RuntimeClasspathResourceHasher.java:46)
        at org.gradle.api.internal.changedetection.state.ZipHasher.fingerprintZipEntries(ZipHasher.java:119)
        at org.gradle.api.internal.changedetection.state.ZipHasher.fingerprintZipEntries(ZipHasher.java:101)
        at org.gradle.api.internal.changedetection.state.ZipHasher.hashZipContents(ZipHasher.java:84)
        at org.gradle.api.internal.changedetection.state.ZipHasher.hash(ZipHasher.java:71)
        at org.gradle.api.internal.changedetection.state.DefaultResourceSnapshotterCacheService.hashFile(DefaultResourceSnapshotterCacheService.java:45)
        at org.gradle.api.internal.changedetection.state.SplitResourceSnapshotterCacheService.hashFile(SplitResourceSnapshotterCacheService.java:43)
        at org.gradle.internal.fingerprint.classpath.impl.ClasspathFingerprintingStrategy.fingerprintZipContents(ClasspathFingerprintingStrategy.java:191)
        at org.gradle.internal.fingerprint.classpath.impl.ClasspathFingerprintingStrategy.fingerprintRootFile(ClasspathFingerprintingStrategy.java:184)
        at org.gradle.internal.fingerprint.classpath.impl.ClasspathFingerprintingStrategy.access$100(ClasspathFingerprintingStrategy.java:64)
        at org.gradle.internal.fingerprint.classpath.impl.ClasspathFingerprintingStrategy$ClasspathContentFingerprintingVisitor.fingerprintFile(ClasspathFingerprintingStrategy.java:160)
        at org.gradle.internal.fingerprint.classpath.impl.ClasspathFingerprintingStrategy$ClasspathContentFingerprintingVisitor.visitFile(ClasspathFingerprintingStrategy.java:149)
        at org.gradle.internal.snapshot.RegularFileSnapshot.accept(RegularFileSnapshot.java:66)
        at org.gradle.internal.fingerprint.classpath.impl.ClasspathFingerprintingStrategy.collectFingerprints(ClasspathFingerprintingStrategy.java:106)
        at org.gradle.internal.fingerprint.impl.DefaultCurrentFileCollectionFingerprint.from(DefaultCurrentFileCollectionFingerprint.java:48)
        at org.gradle.internal.fingerprint.impl.AbstractFileCollectionFingerprinter.fingerprint(AbstractFileCollectionFingerprinter.java:48)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.lambda$visitInputFileProperties$1(ExecuteActionsTaskExecuter.java:326)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$fingerprintInputFiles$3(CaptureStateBeforeExecutionStep.java:192)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.visitInputFileProperties(ExecuteActionsTaskExecuter.java:324)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.fingerprintInputFiles(CaptureStateBeforeExecutionStep.java:188)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.captureExecutionState(CaptureStateBeforeExecutionStep.java:150)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$captureExecutionStateOp$1(CaptureStateBeforeExecutionStep.java:104)
        at org.gradle.internal.execution.steps.BuildOperationStep$1.call(BuildOperationStep.java:40)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:409)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:399)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:94)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
        at org.gradle.internal.execution.steps.BuildOperationStep.operation(BuildOperationStep.java:37)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.captureExecutionStateOp(CaptureStateBeforeExecutionStep.java:103)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$execute$0(CaptureStateBeforeExecutionStep.java:78)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:78)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:53)
        at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:74)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:78)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:78)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:39)
        at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:40)
        at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:28)
        at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:194)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:186)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:114)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:409)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:399)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:94)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:356)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)


* Get more help at https://help.gradle.org

BUILD FAILED in 54s

I updated Bubblewrap to the latest version, removed the existing JDK and SDK and let Bubblewrap re-install the latest, and also deleted my app files (except the keystore), to let Bubblewrap rebuild everything from scratch.

So, it should be pretty clean!

I've also updated gradlew.bat:

set DEFAULT_JVM_OPTS="-Xmx1536m" "-Xms1536m"

And this is what I have in gradle.properties:

org.gradle.jvmargs=-Xmx1536m

To Reproduce
..\node_modules\.bin\bubblewrap build

Expected behavior
Successful build.

Desktop:
Windows 11
Running on Visual Studio Code.

@ghnp5
Copy link
Author

ghnp5 commented Aug 25, 2023

If I increase the RAM allowed even more, then I simply get these minimal logs, not really saying what the problem is:

Building the Android App...

cli ERROR Command failed: gradlew.bat assembleRelease --stacktrace

Passing --info or --debug to the Bubblewrap's build command doesn't really do anything either.

Even changing GradleWrapper.js doesn't help either:

    async assembleRelease() {
        await this.executeGradleCommand(['assembleRelease', '--stacktrace', '--info', '--debug']);
    }

cli ERROR Command failed: gradlew.bat assembleRelease --stacktrace --info --debug

All logs suppressed.

--

Only when I call directly:

gradlew.bat assembleRelease --stacktrace --info --debug

That's when I get proper useful logs:

  • What went wrong:
    Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
    SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable

--

The location in ~\.bubblewrap\config.json is correct, so I'm not sure why the environment variable isn't being set.

@ghnp5
Copy link
Author

ghnp5 commented Aug 25, 2023

I manually set the environment variable.

I get the OutOfMemory error again, if I keep it at 1536m.

If I increase to 2048, I get this...

> ./gradlew.bat assembleRelease --stacktrace
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap

--

I'm reading that I can only allocate 1.6GB if I'm using 32bit version of JVM or so. Is it what Bubblewrap downloads?

Anyway - I assume we're not supposed to have to allocate so much memory, so this "OutOfMemory" must be a consequence of something else, but I haven't figured out what...

--

EDIT - I've just created a new project... no changes at all... and still get "OutOfMemory".

@ghnp5
Copy link
Author

ghnp5 commented Aug 25, 2023

Alright... looks like it works with Docker (I used your Dockerfile)

So I'll just keep building that way!! :)

Thank you!

(keeping this issue open anyway, in case there's some fix needed for Windows)

@hslee2008
Copy link
Contributor

It went a bit different for me.

cli ERROR Command failed: gradlew.bat assembleRelease --stacktrace

FAILURE: Build failed with an exception.

* What went wrong:
Metaspace

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
java.lang.OutOfMemoryError: Metaspace


* Get more help at https://help.gradle.org

BUILD FAILED in 2s

@ghnp5
Copy link
Author

ghnp5 commented Aug 27, 2023

Yeah, I recall getting that one too.

@dreamunlim
Copy link

I would like to add that in my case both the "OutOfMemory" and "Metaspace" errors vanished on PC restart after the fresh install of v1.21.0.

Instead, the Bubblewrap started failing to generate an .aab bundle, though .apk gets generated successfully.

The error given:

Building the Android App...
        - Generated Android APK at ./app-release-signed.apk


cli ERROR spawn jarsigner ENOENT

If it helps: Windows 10 64bit, 3.8GB usable RAM, jdk-11.0.20+8 32bit.

@hslee2008
Copy link
Contributor

I am pretty sure this might be only related to Windows. With the exact setup and versions, I was able to succeed in Linux. Not sure about Mac.

@StillOnMyWay
Copy link

Running a debian Linux machine, getting the same error for jarsigner ENOENT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants