Container 'Build' exceeded memory limit. Android
Asked by Krunal Pandav:

Hi,  
I'd like to ask you about my memory overflow problem.  
I tried something but it didn't help. Sometimes it passes and sometimes it doesn't. This is a mystery to me.  
Can you please give me some advice?  
currently my repository size is 2.11 GB is it can matter for pipeline?  
Thank you very much.  

<br />

image: androidsdk/android-30  
definitions:  
services:  
docker:  
memory: 512  
docker-with-more-memory:  
memory: 2048  
type: docker  
docker-with-large-memory:  
memory: 5120  
type: docker  
pipelines:  
branches:  
master:  
#- parallel:  
- step:  
size: 2x  
name: Build  
caches:  
- gradle  
script:  
- echo "$GOOGLE_SERVICES_JSON" \| base64 -di \> app/google-services.json  
- echo "$SIGNING_JKS_FILE" \| base64 -di \> android-signing-keystore.jks  
- ./gradlew assembleRelease  
artifacts:  
- app/build/outputs/\*\*  
- step:  
size: 2x  
name: Build Debug  
caches:  
- gradle  
script:  
- echo "$GOOGLE_SERVICES_JSON" \| base64 -di \> app/google-services.json  
- echo "$SIGNING_JKS_FILE" \| base64 -di \> android-signing-keystore.jks  
- ./gradlew assembleDebug  
artifacts:  
- app/build/outputs/\*\*  
- step:  
size: 2x  
name: Test  
caches:  
- gradle  
script:  
- ./gradlew test  
- step:  
size: 2x  
name: Push On Production  
#trigger: manual  
script:  
- echo "$GOOGLE_SERVICES_JSON" \| base64 -di \> app/google-services.json  
- echo $GOOGLE_API_KEY_JSON \| base64 -di \> google_play_api_key.json  
- echo "$SIGNING_JKS_FILE" \| base64 -di \> android-signing-keystore.jks  
- ./gradlew :app:publishReleaseBundle  
artifacts:  
- app/build/outputs/


Answers:
author: Ben
body: Hey Krunal,

Welcome to the Bitbucket Cloud community!

I would suggest including the following line of code in your bitbucket-pipelines.yml file to the affected step - this will allow you to determine which part of the step is exceeding the build memory limit:

```
- while true; do date && echo "Memory usage in megabytes:" && echo $((`cat /sys/fs/cgroup/memory/memory.memsw.usage_in_bytes | awk '{print $1}'`/1048576)) && echo "" && sleep 30; done &
```

Cheers!

- Ben (Bitbucket Cloud Support)

comments: author: Krunal Pandav
body: I'm getting issue on below step  
- step:  
size: 2x  
name: Test  
caches:  
- gradle  
script:  
- ./gradlew test  

in which section i put this solution?


author: Ben
body: Hey Krunal,

You would put it in the "script" section at the top :)

Cheers!

- Ben (Bitbucket Cloud Support)


author: Krunal Pandav
body: Hey i was update my pipeline with your suggestion but it happen every some time period what is the reason for that what i change for that?  

again I'm getting this "Container 'Build' exceeded memory limit." error.

my pipeline code is below and i'm gettin memory lint error in last step.

image: androidsdk/android-30  
definitions:  
services:  
docker:  
memory: 1024  
docker-with-more-memory:  
memory: 4096  
type: docker  
docker-with-large-memory:  
memory: 10240  
type: docker  
caches:  
gradle:  
key:  
files:  
- build.gradle  
path: \~/.gradle/caches  
pipelines:  
branches:  
master:  
#- parallel:  
- step:  
size: 2x  
name: Build Variants  
caches:  
- gradle  
script:  
- echo "$GOOGLE_SERVICES_JSON" \| base64 -di \> app/google-services.json  
- echo "$SIGNING_JKS_FILE" \| base64 -di \> android-signing-keystore.jks  
- ./gradlew assembleRelease  
- step:  
size: 2x  
name: Build Debug  
caches:  
- gradle  
script:  
- echo "$GOOGLE_SERVICES_JSON" \| base64 -di \> app/google-services.json  
- echo "$SIGNING_JKS_FILE" \| base64 -di \> android-signing-keystore.jks  
- ./gradlew assembleDebug  
- step:  
size: 2x  
name: Push On Production  
script:  
- echo "$GOOGLE_SERVICES_JSON" \| base64 -di \> app/google-services.json  
- echo $GOOGLE_API_KEY_JSON \| base64 -di \> google_play_api_key.json  
- echo "$SIGNING_JKS_FILE" \| base64 -di \> android-signing-keystore.jks  
- while true; do date \&\& echo "Memory usage in megabytes:" \&\& echo $((\`cat /sys/fs/cgroup/memory/memory.memsw.usage_in_bytes \| awk '{print $1}'\`/1048576)) \&\& echo "" \&\& sleep 30; done \&  
- ./gradlew :app:publishReleaseBundle --no-daemon  
please suggest for that what i change ?

comments: author: Ben
body: Hey Krunal,

I've noticed based on your yml config that you've assigned 10240 to the docker-with-large-memory service container.

Pipelines builds have a maximum of 8GB to assign memory for when using the "size: 2x" build step - so the above definition will cause the build to fail automatically as it exceeds the maximum limit.

The 8GB of memory consists of 1GB for the build container, so realistically you only have 7GB total remaining - when you factor in the docker service containers - whichever container is being used is subtracted from this 7GB pool.

This means if you were to have a build step using the docker-with-more-memory service container for example - the remaining memory used by the step container would only be 3GB (8GB - 1GB build container - 4GB service container = 3GB remaining).

I would highly suggest reading through our documentation related to Pipelines, and if you need more than 8GB I would suggest making use of self-hosted runners:

* [Pipelines Configuration Reference](https://support.atlassian.com/bitbucket-cloud/docs/bitbucket-pipelines-configuration-reference/)
* [Pipelines Runners Configuration Reference](https://support.atlassian.com/bitbucket-cloud/docs/runners/)

Cheers!

- Ben (Bitbucket Cloud Support)


author: Krunal Pandav
body: what we define first in definitions section caches or services?


author: Ben
body: Hi [@Krunal Pandav](/t5/user/viewprofilepage/user-id/5059912) I usually define services first and this is what I would recommend. Your issue relates to the assigned memory, however - as per my previous reply.


Tags: bitbucket-cloud

bitbucket-pipelines

cloud