How to install Android SDK and build Android App without Android Studio
Tags: android, reactnative, react, tutorial
Published: 2021-06-13 14:24:54

This article is about installing Android SDK in Windows system and run React Native App without Android Studio. Android SDK is required to build, run and debug Android Apps on your machine. So I needed it too to build and run React Native app for android in my windows system.

***But Android SDK comes with Android Studio!!!*** Yes, you are right but not every system can handle [Android Studio](https://developer.android.com/studio#system-requirements-a-namerequirementsa) :) My system is also behind the minimum system requirements so I had to go for Android SDK separately.

---

## Step 1: Install Chocolatey
In the [official React Native Documentation](https://reactnative.dev/docs/environment-setup), [Chocolatey](https://chocolatey.org/) is recommended for downloading Node and Java. If you already have that downloaded and configured then you can skip this step.

You can either follow the complete [Chocolatey Installation Doc](https://chocolatey.org/install) or just run below command in your ***Windows Powershell Window***.
```sh
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
```
You will get Chocolatey installed and Environment Variables set.

---

## Step 2: Install Java
As per the [official React Native Documentation](https://reactnative.dev/docs/environment-setup),  You can use Chocolatey to install Java. If you already have that, skip this step. Just run below command in command prompt to install Node and Java. You can skip the package you have already installed.
```sh
choco install -y nodejs.install openjdk8
```
Now you must have `JAVA_HOME` set in your environment variables, if not then you can set. To go to environment variable you can follow below steps:

1: Go To *Properties*:
![Properties](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9e86gd3vhtu2pzcp4dti.png) 

2: Go to Advance System Settings
![AdSySt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69c10q8gz6b71rrvv0bv.png)

3: Go to Environment Variables
![EV](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4yu6idd01cf38xc80m2.png)

4: List of Environment Variables can be accessed here
![EV](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tchcvv9u4i4cphye6sab.png)

___

## Step 3: Install SDK Manager
Now firstly we need to install [Android SDK Manager](https://developer.android.com/studio/command-line/sdkmanager) to install Android SDK and other tools. For that [visit the official site](https://developer.android.com/studio#span-idcommand-toolsa-namecmdline-toolsacommand-line-tools-onlyspan).

**1.** Download `sdkmanager` compressed file.
![CLT](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sfrq4nq7jbqyi44lau6g.png)

**2.** Now you need to create a folder, where you want to keep your all SDK packages. I created `C:\Android` for my case. Unzip the downloaded folder in this directory. Now I'm having the folder structure as `C:\Android\cmdline-tools\<unzipped files>`.

**3.** ***IMPORTANT:*** Now, we need to move all the unzipped files in a single folder. the name of the folder will be determined by the `source.properties` file's content, which is one of these unzipped files. Open this file and It'll be looked like this:
```txt
Pkg.Revision=4.0
Pkg.Path=cmdline-tools;4.0
Pkg.Desc=Android SDK Command-line Tools
```
Notice the first line, the value `4.0` is going to be our folder name.

So create a folder named as `4.0` 	inside `C:\Android\cmdline-tools\` and move all other files into this folder. So now full directory structure will be `C:\Android\cmdline-tools\4.0\<bin | lib>`.

**4.** Now we'll set 2 Environment variables: `ANDROID_HOME` and `Path` for `cmdline-tools`.
* Set `ANDROID_HOME` to the path of the directory you made in above point 2, in my case it's `C:\Android`.
![Android_HOME](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ux3wi951lhq2u42ahmfp.png)

* Add `C:\Android\cmdline-tools\4.0\bin` and `C:\Android\cmdline-tools\4.0` in `Path` Variable.
![cmdline_tools](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qldrcbpnt6ke2dyicmgx.png)


___

## Step 4: Install Android SDK packages
We'll now install the required packages via `sdkmanager`. For that, open Command Prompt.

### 1. Install Platform Tools (ADB & Fastboot)

Firstly we need to install [`adb`](https://developer.android.com/studio/command-line/adb), for that we can install `platform-tools` pkg via `sdkmanager`. Run below command or get it from [here](https://developer.android.com/studio/releases/platform-tools).
```sh
sdkmanager "platform-tools"
```

Now add path of `platform-tools` in Environment Variable `Path` which is `C:\Android\platform-tools` in my case.

---

### 2. Install Platform
Use the below command to install the Android 10 (API level 30) using the SDK manager. You can download any API level by changing the name.
```sh
sdkmanager "platforms;android-30"
```
Aceept T&C and it'll be installed.

---

### 3. Add System Image
I am adding the most recent default 64-bit system image by running below command. Accept T&C and it'll be installed.
```sh
sdkmanager "system-images;android-30;google_apis;x86_64"
```

There are some projects which need Google Play Services. We need system image specific to Google Play Services. We can add that via command as shown below.
```sh
sdkmanager "system-images;android-30;google_apis_playstore;x86_64"
```

---

### 4. Install Build Tools
I am adding the most recent `build-tools` `30.0.3` via below command.
```sh
sdkmanager "build-tools;30.0.3"
```

---

### 5. Install Emulator (Optional)
If you want to run your apps inside emulator instead of physical device then you can install emulator and system images to run that. But obviously, it requires good system specs. We'll cover this in very short, please comment if you want detailed article on that.

**1.** Install Emulator
```sh
sdkmanager --channel=3 emulator
```

**2.** Create emulator
```sh
// Create the emulator with name em30 using default system image
avdmanager create avd -n em30 -k "system-images;android-30;google_apis;x86_64" -g "google_apis"

// Create emulator with name em30ps using Google Play Services system image
avdmanager create avd -n em30ps -k "system-images;android-30;google_apis_playstore;x86_64"
```
This will ask many questions, answer as per yoyr need.

**3.** Add emulator path in `Path` environment variable, in my case it's `C:\Android\emulator`.

**4.** List emulator devices installed
```sh
emulator -list-avds
```

**5.** Run emulator
```sh
// Run Emulator named em30
emulator -avd em30
```

---

### 6. How to use my device instead of emulator
You can follow the official documentation [here](https://reactnative.dev/docs/running-on-device) and a related troubleshooting [here](https://stackoverflow.com/a/60304825/8494462). I'll be adding article for my version of the same soon.

---

So everything is set now and you'll be having Android SDK set up in your system. Below are some other related and useful commands.

```sh
// list all packages available in sdkmanager
sdkmanager --list

// list installed packages via sdkmanager
sdkmanager --list_installed

// Update installed packages
sdkmanager --update

// Uninstall packages
sdkmanager --uninstall <package name>

// Delete Emulator
avdmanager delete avd -n <emulator name>
```
Cover Photo by [Denny Müller](https://unsplash.com/@redaquamedia?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/android?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)