After reviewing Buck in a previous post, it was time to check out Bazel. Bazel is the open-source version of Google’s internal Blaze build system (and for the record, Buck was inspired by Blaze).
I’m going to have a few posts about Bazel in the journy to convert a project into Bazel from Gradle.

Why

Well, given you have an existing Android project; it is probably being built with Gradle. It’s working, it’s stable, and it has all kind of neccesery tasks you are depending on. Which make converting to Bazel (or any other build system) quite a block.
So let’s try to have our project support both Bazel and Gradle at the same time.

Pre-requisites

For our posts, let’s say that we have an awesome Android app - currently built using Gradle - that we want to convert to Bazel. We’ll use this git repo for our posts, and here is the app’s initial state (simple Android app, built with Gradle).

The Problem

Bazel two type of files that define the build:

  • WORKSPACE - which defines the global build properties (like SDK path), and defines external repos (libraries) which can be used in our build.
  • BUILD - which defines a module in our build, and how to build it. A module can be a library, content, or binary (our app).

Well, Gradle default build output folder is called build, and on some OSes (I’m looking at you, MacOSX), the filesystem can be set (or default) to be case-insensitive. This introduces the issue of Gradle-Bazel: both require a file-system object named build. This is, of course, not an issue for Linux, but it is an issue for MacOSX.

What to do?

Unlike Bazel, Gradle is very configurable: we’ll just tell Gradle to use a different folder name for its build outputs. This is done by adding buildDir = 'gen_build' to our build.gradle file, and revising the .gitignore settings.

Here is the commit that fixes this for our awesome demo app.


blog comments powered by Disqus