Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android Wiki] Fix Part of #2746 : Added Bazel Installations instructions for different Operating System #4926

Merged
merged 27 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3de1455
Added Bazel Installations instructions for different OS
MohitGupta121 Mar 28, 2023
4b51cfa
Fixed review changes of Sean
MohitGupta121 Mar 29, 2023
c5b270e
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Mar 30, 2023
212bfdb
Remove windows instructions from Mac
MohitGupta121 Mar 31, 2023
f011a49
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Mar 31, 2023
41d86da
Updated review changes
MohitGupta121 Mar 31, 2023
ffbbf18
Fixed minor changes
MohitGupta121 Mar 31, 2023
dbe3738
Merge android_home into step 6
MohitGupta121 Mar 31, 2023
18d5806
updated some review changes
MohitGupta121 Mar 31, 2023
bea29a1
Minor changes.
MohitGupta121 Mar 31, 2023
e7bd44b
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Apr 8, 2023
d22214d
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Apr 15, 2023
36bd499
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Apr 16, 2023
37de85a
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Apr 23, 2023
8ce56a2
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 May 1, 2023
078cdfe
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 May 8, 2023
84e82ee
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 May 15, 2023
d6a683a
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 May 21, 2023
802c574
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 May 28, 2023
f08682e
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Jun 3, 2023
67f525c
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Jun 6, 2023
b624ba5
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Jun 9, 2023
54a72b5
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Jun 11, 2023
e183b6a
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Jun 18, 2023
ddf960d
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Jun 26, 2023
8722dfd
Merge branch 'develop' into bazel_installation_wiki
MohitGupta121 Jun 28, 2023
382d31c
make review changes
MohitGupta121 Jun 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions wiki/Bazel-Setup-Instructions-for-Linux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## Instructions

**The steps to install Bazel on Linux are:**
1. Install Bazel
2. Install OpenJDK 8
3. Install Python 2 and make sure it is active in your environment
4. Set up the ANDROID_HOME environment variable
5. Prepare the build environment
6. Verify the Android build

### 1. Install Bazel

Install Bazel from [here](https://docs.bazel.build/versions/master/install.html). Make sure that you follow the instructions for installing a specific version (Oppia Android requires 4.0.0 and won't build on other versions).
- Note: if you find any errors related to `cURL`, please set up cURL on your machine. For Linux, you can use `sudo apt install curl`.

### 2. Install OpenJDK 8

Oppia Android also requires OpenJDK 8. The Bazel installation instructions above include [sections on installing OpenJDK](https://docs.bazel.build/versions/main/tutorial/java.html#install-the-jdk) on different platforms.

- You can run the following to install OpenJDK 8:

```sh
sudo apt install openjdk-8-jdk
```

You can confirm that this is set up using the command `java -version`, which should result in three lines being printed out with the first one showing "openjdk version "1.8.0_292".

### 3. Install Python 2

Ensure that you have Python 2 installed and make sure that it is currently active on your environment. You can do this by using the ``python --version`` command which should show Python 2.X.X. If it doesn’t, click [here](https://linuxconfig.org/install-python-2-on-ubuntu-20-04-focal-fossa-linux) for a resource on how to install and update Linux to use Python 2.

### 4. Set up the ANDROID_HOME environment variable

Ensure that your `ANDROID_HOME` environment variable is set to the location of your Android SDK. To do this, find the path to the installed SDK using Android Studio’s SDK Manager (install SDK 28). Assuming the SDK is installed to default locations, you can use the following commands to set the `ANDROID_HOME` variable:<br>
```
export ANDROID_HOME=$HOME/Android/Sdk/
```
- **Make sure you have the system environment variable set up** for ``ANDROID_HOME`` as you might have issues getting properly set up if not. If it isn’t set up (on Linux you can check by using ``echo $ANDROID_HOME`` in a new terminal; it should output the correct path to your Android SDK), on Linux you can move the ``export`` from above to your ``~/.bashrc`` file to make it permanent (you can apply the change immediately using ``source ~/.bashrc``).

### 5. Prepare the build environment

Follow the instructions in [oppia-bazel-tools](https://github.com/oppia/oppia-bazel-tools).

### 6. Verifying the build

At this point, your system should be able to build Oppia Android. To verify, try building the APK (from your subsystem terminal -- note that this and all other Bazel commands must be run from the root of the ‘oppia-android’ directory otherwise they will fail):

```sh
bazel build //:oppia
```

(Note that this command may take 10-20 minutes to complete depending on the performance of your machine).

If everything is working, you should see output like the following:

```
Target //:oppia up-to-date:
bazel-bin/oppia_deploy.jar
bazel-bin/oppia_unsigned/apk
bazel-bin/oppia/apk
INFO: Elapsed time: ...
INFO: 1 process...
INFO: Build completed successfully, ...
```

If you see the above, you can proceed to use your subsystem for Bazel commands while developing Oppia. If you instead see an error, please [file an issue](https://github.com/oppia/oppia-android/issues/new/choose).

Note also that the ``oppia.apk`` under the ``bazel-bin`` directory of your local copy of Oppia Android should be a fully functioning development version of the app that can be installed using ``adb``
105 changes: 105 additions & 0 deletions wiki/Bazel-Setup-Instructions-for-Mac.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
## Bazel Set up for Mac including Apple silicon (M1/M2) chips

## Instructions

**The steps to install Bazel on Mac are:**
1. Set up Rosetta Terminal
2. Install Bazel
3. Install OpenJDK 8
4. Install Python 2 and make sure it is active in your environment
5. Set Bazel, Python 2, ANDROID_HOME paths permanently in your terminal
6. Prepare the build environment
7. Verify that the build is working

### 1. Set up Rosetta Terminal

- In the Finder app on your Mac, locate the Applications folder from the favorites sidebar.
- Right-click on your Terminal app and create a duplicate Terminal (and rename it accordingly, say **Terminal Rosetta**, to avoid confusion).
- On the newly created Terminal Rosetta icon, right-click and select "Get info", and under “General”, check the option "Open using Rosetta".

**Note: Always use the Rosetta terminal for Bazel setup and running `bash setup.sh` or any Bazel build-related commands.**

### 2. Install Bazel

1. Install Bazel following the instructions [here](https://docs.bazel.build/versions/4.0.0/install-os-x.html#install-with-installer-mac-os-x). Make sure that you follow the instructions for installing a specific version (Oppia Android requires 4.0.0 and won't build on other versions).

2. That’s it, now Bazel is install, you can check it by running the command:
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
```
bazel --version
```
- **Expected Output**
```
bazel 4.0.0
```

### 3. Install OpenJDK 8

Oppia Android also requires OpenJDK 8.
Follow the instructions [here](https://installvirtual.com/install-openjdk-8-on-mac-using-brew-adoptopenjdk/) to install OpenJDK 8.
Note that this requires the installation of brew as a pre-requisite, which can be done by following the instructions [here](https://mac.install.guide/homebrew/index.html). You can then set up your `$JAVA_HOME` environment variable using these [instructions](https://stackoverflow.com/a/75167958/11396524).


### 4. Install Python 2 and make sure it is active in your environment

To install Python 2 in MacOS follow the follows the commands given below. Note that this requires installation of brew as a pre-requisite, which can be done by following the instructions [here](https://mac.install.guide/homebrew/index.html).
```
seanlip marked this conversation as resolved.
Show resolved Hide resolved
brew install pyenv
pyenv install 2.7.18
pyenv global 2.7.18
```

- To make sure Python 2 is successfully installed and active in your environment, navigate to the **oppia-android** directory and run the following commands:

```
export PATH="$(pyenv root)/shims:${PATH}"
python --version
```

### 5. Set Bazel, Python 2, ANDROID_HOME paths permanently in your terminal

- To set the `Bazel`, `Python 2`, `ANDROID_HOME` path permanently in your terminal run these commands:
```
sudo nano /etc/paths
```
- Enter your password, when prompted.
- Go to the bottom of the file, and enter these paths
```
/Users/{YourMacUserName}/bin
$(pyenv root)/shims:${PATH}
$HOME/Library/Android/sdk
```
- Hit control-x to quit.
- Enter “Y” to save the modified buffer.
- That’s it! To test it, in a new terminal window, type: `echo $PATH`

**Note: You must set the path for `Bazel`, `Python 2`, `ANDROID_HOME` before running bazel build for oppia-android, otherwise you will get an error.**
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved

### 6. Prepare the build environment

Follow the instructions in [oppia-bazel-tools](https://github.com/oppia/oppia-bazel-tools#readme), in order to prepare your environment to support Oppia Android builds.

### 7. Verify that the build is working

At this point, your system should be able to build Oppia Android. To verify, try building the APK (from your subsystem terminal -- note that this and all other Bazel commands must be run from the root of the ‘oppia-android’ directory otherwise they will fail):

```sh
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
bazel build //:oppia
```

(Note that this command may take 10-20 minutes to complete depending on the performance of your machine).

If everything is working, you should see output like the following:

```
Target //:oppia up-to-date:
bazel-bin/oppia_deploy.jar
bazel-bin/oppia_unsigned/apk
bazel-bin/oppia/apk
INFO: Elapsed time: ...
INFO: 1 process...
INFO: Build completed successfully, ...
```

If you see the above, you can proceed to use your subsystem for Bazel commands while developing Oppia. If you instead see an error, please [file an issue](https://github.com/oppia/oppia-android/issues/new/choose).
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved

Note also that the ``oppia.apk`` under the ``bazel-bin`` directory of your local copy of Oppia Android should be a fully functioning development version of the app that can be installed using ``adb``
16 changes: 16 additions & 0 deletions wiki/Bazel-Setup-Instructions-for-Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ JDK 8 is required for the Android build tools, and we suggest installing OpenJDK
sudo apt install openjdk-8-jdk-headless
```

#### For Fedora 25+
- Install JDK 8 by running this command on the terminal:
```
sudo dnf install java-1.8.0-openjdk
```
- Set the default Java version to jdk-8 by running the following command `sudo update-alternatives --config java` and selecting the number with jdk-8.

**Python 2**

Unfortunately, some of the Bazel build actions in the Android pipeline require Python 2 to be installed:
Expand Down Expand Up @@ -131,6 +138,15 @@ Follow [these instructions](https://docs.bazel.build/versions/main/install-ubunt
sudo apt install bazel-4.0.0
```

#### For Fedora 25+

- Install Bazelisk instead of Bazel using the command below in Fedora:
```
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.8.1/bazelisk-linux-amd64
chmod +x bazelisk-linux-amd64
sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel
```

### 5. Preparing build environment for Oppia Android

The Oppia Android repository generally expects to live under an 'opensource' directory. While we recommend doing that in practice, we run into one complication when building the app on Windows: the repository itself lives under the native Windows filesystem & most of everything else needed to build lives under the Linux subsystem. To help simplify things, we prefer keeping just the repository on Windows and everything else on Linux, including the the Oppia Bazel toolchain. To prepare for this, we suggest making an 'opensource' directory in your Ubuntu subsystem:
Expand Down
39 changes: 7 additions & 32 deletions wiki/Oppia-Bazel-Setup-Instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,19 @@
## Overview
Bazel is an open-source build and test tool similar to Make, Maven, and Gradle. It uses a human-readable, high-level build language.

## Installation
### Installation

**WARNING: We recommend to not use the Android Studio Bazel plugin since it currently has compatibility issues with the project.**

**NOTE: If you're using Windows, please follow [these instructions](https://github.com/oppia/oppia-android/wiki/Bazel-Setup-Instructions-for-Windows) instead.**
**Instructions for setting up Bazel on different Operating Systems:**

Instructions for setting up Bazel on Unix-based machines:
- [For Windows/Ubuntu/Fedora](https://github.com/oppia/oppia-android/wiki/Bazel-Setup-Instructions-for-Windows)
- [For Mac including M1/M2](https://github.com/oppia/oppia-android/wiki/Bazel-Setup-Instructions-for-Mac)
- [For Linux](https://github.com/oppia/oppia-android/wiki/Bazel-Setup-Instructions-for-Linux)

1. Install Bazel from [here](https://docs.bazel.build/versions/master/install.html). Make sure that you follow the instructions for installing a specific version (Oppia Android requires 4.0.0 and won't build on other versions).
- As of February 2023 we have verified that on Ubuntu (and similar systems) the [apt repository approach](https://bazel.build/install/ubuntu#install-on-ubuntu) works, you just need to make sure to do `sudo apt install bazel-4.0.0` as the latest command to install the correct version.
- Note: if you find any errors related to `cURL`, please set up cURL on your machine. For Linux, you can use `sudo apt install curl`.
### Building the app


2. Oppia Android also requires OpenJDK 8. The Bazel installation instructions above include [sections on installing OpenJDK](https://docs.bazel.build/versions/main/tutorial/java.html#install-the-jdk) on different platforms.

- For example, if you're using Ubuntu or another Debian-based system, you can run the following to install OpenJDK 8:

```sh
sudo apt install openjdk-8-jdk
```

- For MacOS M1, follow the instructions [here](https://installvirtual.com/install-openjdk-8-on-mac-using-brew-adoptopenjdk/). Note that, this requires installation of brew as a pre-requisite, which can be done by following the instructions [here](https://mac.install.guide/homebrew/index.html).

You can confirm that this is set up using the command `java -version`, which should result in three lines being printed out with the first one showing "openjdk version "1.8.0_292".

3. Ensure that you have Python 2 installed and make sure that it is currently active on your environment. You can do this by using the ``python --version`` command which should show Python 2.X.X. If it doesn’t, click [here](https://linuxconfig.org/install-python-2-on-ubuntu-20-04-focal-fossa-linux) for a resource on how to install and update Ubuntu to use Python 2 (other distros may vary in this step slightly).

4. Ensure that your `ANDROID_HOME` environment variable is set to the location of your Android SDK. To do this, find the path to the installed SDK using Android Studio’s SDK Manager (install SDK 28). Assuming the SDK is installed to default locations, you can use the following commands to set the `ANDROID_HOME` variable:<br>
- Linux: `export ANDROID_HOME=$HOME/Android/Sdk/`<br>
- macOS: `export ANDROID_HOME=$HOME/Library/Android/sdk`
- **Make sure you have the system environment variable set up** for ``ANDROID_HOME`` as you might have issues getting properly set up if not. If it isn’t set up (on Linux you can check by using ``echo $ANDROID_HOME`` in a new terminal; it should output the correct path to your Android SDK), on Linux you can move the ``export`` from above to your ``~/.bashrc`` file to make it permanent (you can apply the change immediately using ``source ~/.bashrc``).

5. Follow the instructions in [oppia-bazel-tools](https://github.com/oppia/oppia-bazel-tools).


#### Building the app

After the installation, completes you can build the app using 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:

Expand Down