We are going to run the Gradle cache node locally(container) then run Gradle tasks. We can see that every time we run the Gradle tasks it’s faster since it’s caching Android build steps.

  1. Gradle cache Docker container configuration.
  2. Android Studio configuration.
  3. Run Gradle tasks.
  1. Install Docker and read Gradle cache manual.

2. Create a new local directory to store Gradle Cache data entries. Ex: /user/dev/DockerCache

3. Start the Docker Application and run below docker command to initiate Gradle cache node locally.

docker run -d -v /Users/asandoval/DockerCache/data:/data -p 80:5071 gradle/build-cache-node:latest

4. Check docker process with below command:

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS

c5532d190b13 gradle/build-cache-node:latest “build-cache-node” 14 seconds ago Up 13 seconds 0.0.0.0:80->5071/tcp

5.Open chrome http://0.0.0.0/

6. Create a new User: go to Build cache -> Settings -> create a new user (You will need the user credentials for next step below configuring Gradle cache inside Android Studio project)

  1. Add flag to gradle.properties:
org.gradle.caching=true

2. Add to settings.gradle: (add your new User credentials)

ext.isCiServer = "true"buildCache {
local {
enabled = !isCiServer
}
remote(HttpBuildCache) {
url = 'http://0.0.0.0/cache/'
push = isCiServer
credentials {
username = 'andres'
password = 'pass'
}
}
}

Once you configured “Gradle Cache node” and “Android Studio”, run a Gradle task from the terminal and you can see the task runs faster every time.

./gradlew assembleGoogleFlavorMyAppFreeFatDebug
We can see the Cache entries increases every time we run a Gradle task

Open chrome 0.0.0.0:80 and you can see the build cache size increase, and can purge container data.

Thanks for reading! :)

Notes: Limitations currently Unit test, Instrumented test(Espresso), and Lint are not currently cacheable but others part of Android are cached, according to documentation the task will be cacheable on later Android Gradle Plugin releases.

Resources:

caching tests info min 7–8.

Docker commands:

docker build -t friendlyhello .  # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyhello # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello # Same thing, but in detached mode
docker container ls # List all running containers
docker container ls -a # List all containers, even those not running
docker container stop <hash> # Gracefully stop the specified container
docker container kill <hash> # Force shutdown of the specified container
docker container rm <hash> # Remove specified container from this machine
docker container rm $(docker container ls -a -q) # Remove all containers
docker image ls -a # List all images on this machine
docker image rm <image id> # Remove specified image from this machine
docker image rm $(docker image ls -a -q) # Remove all images from this machine
docker login # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag # Tag <image> for upload to registry
docker push username/repository:tag # Upload tagged image to registry
docker run username/repository:tag # Run image from a registry

Gradle cache Enterprise:

software engineer, read, swim, travel. apps: https://goo.gl/rDuuQw https://goo.gl/15GvfE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store