Lock Your Dependencies With Docker: How This Saved My Old Project React Native Android Build

Kalizi <Andrea>
Apr 1 · 3 min read

“Programming is about managing complexity: the complexity of the problem, laid upon the complexity of the machine. Because of this complexity, most of our programming projects fail.” ~ Bruce Eckel

We all have that nightmare, an old project coming back from the grave for some reason.

Some days ago, I got a call from a customer, that never paid for maintenance, asking for “a simple edit”. And it was easy, I just had to edit a regular expression and trigger a build.

And there, lying behind that simple edit, waiting, was the Android Studio Build. Once I pressed that button, all my problems started.

The last project commit was from September ’19, more than a year ago. And according to npm repositories, for that project were: 20 major updates, 12 minor updates and 6 patches.

Updating everything wasn’t an option: the customer didn’t want to pay for that. So I had to find a way to build the project in the fastest possible way.

Rebuilding September ’19 environment

This was the challenge, rebuild the exact setup I had on September ’19 without breaking my current setup.

Recently, less than 3 months ago, I started using docker. I really wanted to learn how Docker and containerization work, but I didn’t have enough time, so I embraced the philosophy “use first, learn later”.

I never considered using it for Android development, but… why not?

I’m not a dockerist, so I started searching on Google and I found an interesting Github repository from react-native-community.

I grabbed the Dockerfile from the repository and put that on my project.

That was a starting point. Now I needed tweaking:

  • I didn’t need Buck, so I just removed it.
  • I didn’t need the NDK, trashed that too.
  • Dependency versions weren’t the ones I needed, so I changed them.

After these tweaks, I didn’t change anything.

Now build the container and run it!

docker build -t project-android-build .

In my environment, 4 cores and 2048MB of RAM on WSL2, it took 816.3s.

docker run --name=running_container -v F:\Projects\my-app:/app -it project-android-build

I had my September ’19 environment!

It’s time for a build

Everything was set up and ready. I needed to install dependencies with yarn install and to trigger the build for my project

cd android && ./gradlew clean && cd .. && npx jetify && cd android && ./gradlew bundleRelease

If you’re lucky as I was, you’ll finally have your bundle ready.

A final thought on Docker

Photo by Ugur Peker on Unsplash

Well, if I have to summarize what I think in just a few words I would say “It’s amazing”.

Docker provides a simple throwaway development environment that you can spin up, use anytime you need it and finally, thrash and spin up again when needed. It’s amazing because even if the project keeps collecting dust for a while, the next time I need to edit another regex, I can just spin the container up again and rebuild. I can even delete the image and rebuild it if every mirror stays up. That’s, in my opinion, the real power of docker, set your environment, change your project!

Geek Culture

Proud to geek out. Follow to join our +500K monthly readers.

Kalizi <Andrea>

Written by

IT Engineering Bachelor and still student 🎓 Mobile&Backend Dev 💻 Growth hacking Enthusiast ☕ Startupper 🚀 Metalhead 🤘🏻 With love, from Palermo ❤️

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Kalizi <Andrea>

Written by

IT Engineering Bachelor and still student 🎓 Mobile&Backend Dev 💻 Growth hacking Enthusiast ☕ Startupper 🚀 Metalhead 🤘🏻 With love, from Palermo ❤️

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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