Bazel is a new build system developed by Google which allows for an alternative to Gradle for building Android apps. In this guide, I'll show you how you can use Bazel to build your existing Gradle-based Android app.
First we'll start with including RxJava from a remote maven repository. All that's needed is to make the following changes to your WORKSPACE and BUILD files:
Ups! Gambar ini tidak mengikuti Pedoman Konten kami. Untuk melanjutkan publikasi, hapuslah gambar ini atau unggah gambar lain.
Ups! Gambar ini tidak mengikuti Pedoman Konten kami. Untuk melanjutkan publikasi, hapuslah gambar ini atau unggah gambar lain.
The name specified in the maven_jar function should match what is specified in deps, but otherwise can be named however you like. The artifact should be the same as how your dependency is specified in build.gradle, i.e. groupId:artifactId:version.
Including a remote aar from a maven repository
Unfortunately, there is no built-in support for including remote aars with Bazel as of now. If you look at this issue on Github however, there is a workaround github.com/bazel build/bazel/issues/561.
As an example of an aar that you can include in your app, I'll show Timber. There are three steps required in order to include an aar: updating the WORKSPACE, creating a new BUILD file and including the dependency in your app's BUILD.
For your WORKSPACE, you need to add a new_http_archive rule as follows:
Ups! Gambar ini tidak mengikuti Pedoman Konten kami. Untuk melanjutkan publikasi, hapuslah gambar ini atau unggah gambar lain.
The name is like name in maven_jar and the url points to the remote maven repository which hosts the aar. build_file points to the BUILD file which we'll make now for the aar in the same directory as WORKSPACE.
In the timber.BUILD file, include the following:
Ups! Gambar ini tidak mengikuti Pedoman Konten kami. Untuk melanjutkan publikasi, hapuslah gambar ini atau unggah gambar lain.
Most of this file handles building the aar like how an Android app would be built. What happens is that the aar is extracted as part of the build process and then the manifest, resources and classes are packaged up during the build.
Finally, we'll add the dependency to the BUILD files deps:
Ups! Gambar ini tidak mengikuti Pedoman Konten kami. Untuk melanjutkan publikasi, hapuslah gambar ini atau unggah gambar lain.