How to install Android Emulator without Android Studio in Windows10

If you are like me and do not like to install unnecessary software on your machine, then you're at the right place. Recently I wanted to create a React Native app and wanted to install the Android Emulator to test my app. But I did not want Android Studio because I use Visual Code as my IDE. So after a sleepless night of Googling and troubleshooting, I was able to install just Android Emulator manually. I'll share what I found and did in a manner so that you don't have to face the same issues. :)

NOTE: Of course you can just run the emulator with Android Studio without going through all these troubles. But this method will save you your computer memory and speed.

Let's start from the beginning.

Pre-requisites to install Android emulator

1. Java JDK 1.8 or above
2. Android SDK (command line tools)
3. Intel® Hardware Accelerated Execution Manager (Intel® HAXM)

Step 1: Install Java

As you might know, you need Java before doing anything else related to Android. ;) So, go to Oracle Java Download page and download the JDK (not JRE) appropriate for your computer (32-bit or 64-bit version).

Follow installation wizard and install Java on your computer using default settings. If it's successful, the JDK software should be installed on your computer, for example, at C:\Program Files\Java\jdk1.8.0_141. 

Set JAVA_HOME environment variable and add it to path variable.

In Windows 10 search for "Environment Variables" by clicking on Windows logo on TaskBar OR follow below path and screenshot steps 1 to 11.

This PC > Properties > Advanced System Settings > (see below screenshot)

Setting JAVA_HOME in Windows
Setting JAVA_HOME in Windows

Step 2: Install Android SDK

Then you need to download Android SDK command line tools and Android Platform Tools from the official website.

Go to this page and scroll down until you see the heading "Command line tools only". Download SDK tools package for Windows.

Then go to "C:\Users\Paba\AppData\Local" and create a new folder named Android. This will be your Android SDK location (ANDROID_HOME).

Just as you set up JAVA_HOME, you need to create a new User Environment Variable for ANDROID_HOME.

ANDROID_HOME

Then extract the contents of the "sdk-tools-windows-xxxxxxx.zip" file to created Android folder (eg: C:\Users\Paba\AppData\Local\Android. After extracting your Android folder should have a subfolder named "tools".

If you go to C:\Users\Paba\AppData\Local\Android\tools\bin there should be 2 files called "sdkmanager.bat" and "avdmanager.bat". We will be using these 2 to install Android packages and AVDs (Android Virtual Devices).

Step 3: Installing an Android Platform

What are SDK Platforms?

SDK Platforms are the packages that include the Android platform and sources pertaining to an API level. For example, the package we will be installing is Android API Level 26 (also known as Android 8.0 or Oreo). You can also find more details on various SDK Platforms on the official Android website: https://developer.android.com/studio/releases/platforms

Pre-requisite: Run command prompt as Administrator

Open a command prompt as Administrator and navigate to C:\Users\Paba\AppData\Local\Android\tools\bin

Okay!

First of all, you need to find out what are the platforms you can download. So run below command to find them. 

sdkmanager --list

This command will list all the installed packages and available packages. Packages could be add-ons, build-tools, platforms, sources, system-images, extras, and etc. What we are interested here is Platforms. In the long list that came up on your command line, you will see a set of lines like "platforms;android-28" etc.

You need to add "platform-tools" and one of the platforms to proceed. So lets select android-26 as our platform and run below command to download and install them to our SDK.

sdkmanager "platform-tools" "platforms;android-26"

Above command will create 2 new subfolders inside ANDROID_HOME as "platform-tools" and "platforms". 

Bonus Step 3.1: ;-) Troubleshooting

1. Accepting License

You need to accept Android License or otherwise, you'd find an error in your command prompt. Run below command and type "y" to all prompts to proceed with the installation.

sdkmanager --licenses

Now you will see a new subfolder called "licenses" inside ANDROID_HOME.

2. Warning: File C:\Users\Paba\.android\repositories.cfg could not be loaded

If there's a warning as "Warning: File C:\Users\Paba\.android\repositories.cfg could not be loaded." then go to that location and create an empty file named "repositories.cfg".

If you managed to come to this point, then you have successfully installed the Android SDK in your machine. Yey!!! :-D

Next thing you have to install is the Android Emulator. We have done all the above just to get to this!!

But, there's one last thing before moving on to emulator stuff. (Duh!)

That is, you have to have a system image if you want to create an emulator. A system image is a file with an extension ".img". These are also different from Android API level to level. 

So let's add a system image before moving on to creating an emulator.

You can find the available system images in the long list we got earlier by running "sdkmanager --list". Run below command to add a system image relevant to the platform we earlier installed.

sdkmanager "system-images;android-26;google_apis;x86_64"

Now you will be able to see a new subfolder at ANDROID_HOME called "system_images".

Finally, download the "emulator" package. You will see a new subfolder "emulator" in ANDROID_HOME. 

sdkmanager "emulator"

Step 4: Installing HAXM

Download HAXM from intel website and install. This page has a nice documentation on how to install standalone Intel HAXM on Windows. Please follow it if you're unsure what to do. That is not a complicated installation. Before creating the emulator Windows users need to have this installed. Otherwise, you will see below error.

"emulator: ERROR: Missing initial data partition file: C:\Users\Paba\.android\avd\test.avd/userdata.img
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure Windows Hypervisor Platform (WHPX) is properly installed and usable.
CPU acceleration status: HAXM is not installed on this machine"

Step 5: Create an Android Emulator

Up to now, we have only used sdkmanager command line tool. From now on we will be using avdmanager command line tool. Run below command for help.

avdmanager -h

In order to create an AVD you must provide a name for the AVD and specify the ID of the SDK package to use for the AVD using wrapped in quotes. Run below command to create one.

avdmanager create avd -n test_avd_26 -k "system-images;android-26;google_apis;x86_64"

"test_avd_26" is the name. I used "26" in the name itself so that I can instantly find out which API this emulator use.

It'll ask "Do you wish to create a custom hardware profile?" for now select the default (no).

avdmanager list avd

This will list available AVDs. You will see the one you created just now.

Now go to C:\Users\Paba\AppData\Local\Android\emulator and run;

emulator -avd test_avd_26

If all is well, you will see the emulator after a moment.



Comments

  1. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value. Im glad to have found this post as its such an interesting one! I am always on the lookout for quality posts and articles so i suppose im lucky to have found this! I hope you will be adding more in the future... symulator androida

    ReplyDelete

Post a Comment

Popular Posts