-
Notifications
You must be signed in to change notification settings - Fork 521
Oppia Bazel Setup Instructions
Bazel is an open-source build and test tool similar to Make, Maven, and Gradle. It uses a human-readable, high-level build language.
WARNING: We recommend to not use the Android Studio Bazel plugin since it currently has compatibility issues with the project.
-
Download and Install Java 11 using the links from the Java website.
-
Select your Operating System for instructions on setting up Bazel:
After the installation completes you can build the app using Bazel.
Move your command line head to the ~/opensource/oppia-android
, then run the below bazel command:
bazel build //:oppia
bazel build //:oppia && adb install -r bazel-bin/oppia.apk
bazel test //app/...
bazel test //...
See our troubleshooting wiki page for some known issues with Bazel, and the corresponding troubleshooting steps.
Workspace
A workspace is a directory where we add targeted SDK version, all the required dependencies and there required Rules. The directory containing the WORKSPACE file is the root of the main repository, which in our case is the oppia-android
root directory is the main directory.
Packages
A package is defined as a directory containing a file named BUILD or BUILD.bazel.
Binary rules
A rule specifies the relationship between inputs and outputs, and the steps to build the outputs.
In Android, rules are defined using android_binary
. Android rules for testing are android_instrumentation_test
and android_local_test
.
BUILD files
Every package contains a BUILD file. This file is written in Starlark Language. In this Build file for module-level, we generally define android_library
, kt_android_library
to build our package files as per the requirement.
Dependencies
A target A depends upon a target B if B is needed by A at build. A -> B
deps = [ "//app",]
Here, deps
is used to define the dependencies which is a type of dependencies called deps dependencies
and it includes the files/directory/target which are dependent. From the above example the dependency is the app
target which is defined in the Build file of app package.
Example of Dependencies
Loading an extension
Bazel extensions are files ending in .bzl. Use the load statement to import a symbol from an extension.
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")
Here, we are loading android.bzl
and we are going to use it with a symbol name kt_android_library
.
Arguments to the load function must be string literals. load statements must appear at top-level in the file.
Visibility of a file target
With the example from our codebase, target app
whose visibility is public.
-
visibility = ["//visibility:public"],
- Anyone can use this target.
-
"//visibility:private"
- Only targets in this package can use this target.
Testing
when we want to run test cases on Bazel build environment, we usually pass arguments related to test which app_test.bazl
required to run our test.
app_test(
name = "HomeActivityLocalTest",
srcs = ["src/test/java/org/oppia/android/app/home/HomeActivityLocalTest.kt"],
test_class = "org.oppia.android.app.home.HomeActivityLocalTest",
deps = TEST_DEPS,
)
Have an idea for how to improve the wiki? Please help make our documentation better by following our instructions for contributing to the wiki.
Core documentation
Developing Oppia
- Contributing to Oppia Android
- Bazel
- Key Workflows
- Testing
- Developing Skills
- Frequent Errors and Solutions
- RTL Guidelines
- Working on UI
- Writing Design Docs
Developer Reference
- Code style
- Background Processing
- Dark mode
- Buf Guide
- Firebase Console Guide
- Platform Parameters & Feature Flags
- Work Manager
- Dependency Injection with Dagger
- Revert & regression policy
- Upgrading target SDK version
- Spotlight Guide
- Triaging Process
- Bazel
- Internationalization
- Terminology in Oppia
- Past Events