Skip to content

Commit

Permalink
Fix #5324: Updated Wiki Instructions for Bazel Setup Instructions - W…
Browse files Browse the repository at this point in the history
…indows (#5325)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->
Fixes #5324

The provided instructions in [Bazel Setup Instructions for
Windows](https://github.com/oppia/oppia-android/wiki/Bazel-Setup-Instructions-for-Windows)
lack several key components which were added in this PR.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

Special thanks to @sandy99405 for sharing detailed instructions and
@theMr17 for providing additional context!

---------

Co-authored-by: Ben Henning <[email protected]>
  • Loading branch information
Rd4dev and BenHenning authored Feb 6, 2024
1 parent 3ced7e1 commit d04fee4
Showing 1 changed file with 84 additions and 7 deletions.
91 changes: 84 additions & 7 deletions wiki/Bazel-Setup-Instructions-for-Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,36 @@ After that, follow each of the subsections below as needed to install prerequisi

**Java**

JDK 8 is required for the Android build tools, and we suggest installing OpenJDK:
Bazel Setup requires both JDK 8 and JDK>=17 to complete the setup.

- JDK >= 17 is required for [Android Package Manager](#3-installing-the-android-sdk).
- JDK 8 is required for the [Android build tools](#6-verifying-the-build), and we suggest installing OpenJDK.

(Note: Our recommendation is to install both JDK 8 and JDK 17 and always make sure to run sdkmanager commands with JDK 17 and build commands with JDK 8. `sudo update-alternatives --config java` is used to set the default Java version).

**Install JDK 8**

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

#### For Fedora 25+
**Install JDK 17**

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

#### 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.

- Install JDK 17 by running this command on the terminal:
```
sudo dnf install java-17-openjdk
```

#### Follow [these instructions](https://www.java.com/en/download/help/path.html) to correctly set up $JAVA_HOME.

Expand All @@ -76,6 +94,28 @@ Unfortunately, some of the Bazel build actions in the Android pipeline require P
sudo apt install python
```

(This might throw an error - **E**: Package 'python' has no installation candidate)

Alternatively, installl Python 2 using:

```sh
sudo apt install python2
```

To make python2 command accessible as python create a symbolic link from python2 to python:

```sh
sudo ln -s /usr/bin/python2 /usr/bin/python
```

**GCC**

Install gcc using the following command:

```sh
sudo apt install gcc
```

### 3. Installing the Android SDK

We need to be able to run Linux-compatible Android utilities which requires installing a Linux version of the Android SDK. Since we can't install Android Studio in the subsystem, we need to do this via CLI commands. The steps below are extracted from [this article](https://proandroiddev.com/how-to-setup-android-sdk-without-android-studio-6d60d0f2812a).
Expand All @@ -86,10 +126,10 @@ First, prepare the environment for the SDK by creating the default directory to
mkdir -p $HOME/Android/Sdk
```

Second, navigate to https://developer.android.com/studio#command-tools in a web browser (in Windows) and select to download the latest **Linux** command tools (even though you're using Windows, the Linux commandline tools are needed--the Windows version will not work with these instructions). Once downloaded, copy the zip file to the new SDK location (note that the ``/c/mnt/...`` path is based on ``C:\Users\<Name>\Downloads`` being the default download location--this may not be the case on your system) with your Windows username filled in for ``<Name>``:
Second, navigate to https://developer.android.com/studio#command-tools in a web browser (in Windows) and select to download the latest **Linux** command tools (even though you're using Windows, the Linux commandline tools are needed--the Windows version will not work with these instructions). Once downloaded, copy the zip file to the new SDK location (note that the ``/mnt/c/...`` path is based on ``C:\Users\<Name>\Downloads`` being the default download location--this may not be the case on your system) with your Windows username filled in for ``<Name>``:

```sh
cp /c/mnt/Users/<Name>/Downloads/commandlinetools*.zip $HOME/Android/Sdk
cp /mnt/c/Users/<Name>/Downloads/commandlinetools*.zip $HOME/Android/Sdk
```

After that, change to the directory, unzip the archive, and remove it:
Expand Down Expand Up @@ -121,12 +161,23 @@ source ~/.bashrc

(The last line reloads your Bash configuration file so that the variable adjustments above become live in your local terminal).

The ``sdkmanager`` command can now be used to install the necessary packages. Run each of the following commands in succession (you may need to accept licenses for the SDK packages in the same way you would when using Android Studio):
The ``sdkmanager`` command can now be used to install the necessary packages.

**Set the default Java version to JDK-17**

Prior to executing the sdkmanager commands, make sure to set the default Java version to jdk-17 by running the following command:

```sh
sudo update-alternatives --config java
```
Select the number with JDK-17.

Run each of the following commands in succession (you may need to accept licenses for the SDK packages in the same way you would when using Android Studio):

```sh
sdkmanager
sdkmanager --install "platform-tools"
sdkmanager --install "platforms;android-28"
sdkmanager --install "platforms;android-33"
sdkmanager --install "build-tools;29.0.2"
```

Expand Down Expand Up @@ -155,14 +206,40 @@ The Oppia Android repository generally expects to live under an 'opensource' dir

```sh
mkdir $HOME/opensource
cd $HOME/opensource
```

Clone the [oppia-android](https://github.com/oppia/oppia-android) repository into the opensource directory.

```sh
git clone https://github.com/oppia/oppia-android.git
```

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

To configure your development environment and set up essential tools, execute the following setup script from the oppia-android directory.

```sh
scripts/setup.sh
```

### 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 & all other Bazel commands must be run from the root of the ‘oppia-android’ directory otherwise they will fail):

To build, it is necessary to configure JDK 8 as the default. To accomplish this, follow these steps:

**Set Default version to JDK 8**

Prior to executing the build commands, make sure to set the default Java version to jdk-8 by running the following command:

```sh
sudo update-alternatives --config java
```

Select the number with JDK-8

**Build**
```sh
bazel build //:oppia
```
Expand Down

0 comments on commit d04fee4

Please sign in to comment.