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 :) My system is also behind the minimum system requirements so I had to go for Android SDK separately.
You can either follow the complete Chocolatey Installation Doc or just run below command in your Windows Powershell Window.
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.
As per the official React Native Documentation, 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.
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:
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
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:
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
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:
We'll now install the required packages via
sdkmanager. For that, open Command Prompt.
Now add path of
platform-tools in Environment Variable
Path which is
C:\Android\platform-tools in my case.
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.
Aceept T&C and it'll be installed.
I am adding the most recent default 64-bit system image by running below command. Accept T&C and it'll be installed.
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.
I am adding the most recent
30.0.3 via below command.
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
sdkmanager --channel=3 emulator
2. Create emulator
// 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
4. List emulator devices installed
5. Run emulator
// Run Emulator named em30 emulator -avd em30
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.
// 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>