Adding environment variables and java packages to use android studio and emulator.
Tags: android, beginners, tutorial, codenewbie
Published: 2020-12-05 15:42:08

Before you start developing android apps or iOS apps with react native or with java/kotlin with android studio, you have to install a bunch of java stuff and <strong>set environment variables to path variables correctly</strong>.

If you hesitate to do it, you will waste a lot of precious time as I did while scrolling through stack overflow and other forums for hours.

So lets learn how to setup your system for mobile app development.

<strong> Small bit of backstory [Feel free to skip]:</strong>

> I bought a good laptop for college with education loan and I forgot to include all the environment variables and struggled a lot. Now finally, I have configured my machine to compile react native apps and even java/kotlin apps perfectly and run it on an emulator.

This tutorial will almost solve all your installation problems.

<strong><u>First steps:</u></strong>

Forget everything you did before and start fresh!

Install <strong>Java's jre and jdk</strong> by downloading them from the given links below.

I made a big mistake of not downloading and installing jdk and started to get all sorts of errors.

The links to jre and jdk are below.

- [Jre Link](https://www.oracle.com/in/java/technologies/javase-jre8-downloads.html)
- [Jdk Link](https://www.oracle.com/java/technologies/javase-jdk13-downloads.html)

Carefully select the version and your OS specific ones and download and install them.

Now go to environment variables in your system and do as below.

![chrome-capture (24)](https://dev-to-uploads.s3.amazonaws.com/i/zwh8tywa47iu9w7gi9m6.gif)

Type the exact variable as I am typing here.
 
In Environment variables set JAVA_HOME to the location of your jdk and not jre.

<code> JAVA_HOME --> C:\Program Files\Java\jdk-12.0.1</code>

![chrome-capture (29)](https://dev-to-uploads.s3.amazonaws.com/i/euqq8y30dgdm6i6oxoo7.gif)

Now download android studio from the link below.

[Android-Studio Link](https://developer.android.com/studio)

After installing the android SDK along with the android studio, we have to set its path to environment variables.

Do the same as you did with Java jdk here as well.

![chrome-capture (26)](https://dev-to-uploads.s3.amazonaws.com/i/9bytrkufd6s8w0ue38n0.gif)

<code> ANDROID_HOME --> C:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk</code>

After doing that, you need to add three other SDK paths to the path variable like below.

You have to add,

- The path to emulator,
<code>C:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\emulator</code>
- The path to the bin,
<code>C:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\tools\bin</code>
- The path to the platform tools,
<code>C:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\platform-tools</code>

![chrome-capture (28)](https://dev-to-uploads.s3.amazonaws.com/i/a03cfo703lu709vk3au0.gif)
 

After doing all the above steps carefully in the right place, you can now now build android apps without any issues.



Keep in mind to do all these steps again when you buy a new system, or you will really have a tough time figuring out what is the problem.

Now to access the emulators in the avd manager via the terminal, You can use the below code.

To list all the emulators,

```js

emulator -list-avds

```
To start an the emulator,

```js

emulator -avd name

```

To check the connected adb devices

```js

adb devices.

```

Now if we want to sign our developed app and publish it to the playstore, we need to download gradle.

Here is the link to the [official gradle website](https://gradle.org/install/):[gradle](https://gradle.org/install/)

Now after manually downloading the latest gradle package, we need to set it to the environment variables, so do as below,

1 .Extract the downloaded winrar file to program files in C drive.

2. After that we have to set two environmental variables. One is 
<code> GRADLE_HOME = C:\Program Files\gradle-6.7.1 </code>

Another one is 

<code>Path variable > new > C:\Program Files\gradle-6.7.1\bin</code>

![chrome-capture (39)](https://dev-to-uploads.s3.amazonaws.com/i/ymp8hyeqblj4w3vvovc4.gif)


![chrome-capture (40)](https://dev-to-uploads.s3.amazonaws.com/i/mq08ckz0wo88t1j6jurq.gif)
 

After doing these steps, you can easily sign an apk with gradle and publish it to playstore.

Now to check whether the apk is signed or not we can use <strong>jarsigner</strong>

So now include the jdk/bin in the environment path variables.

The jdk bin will be located at<code>C:\Program Files\Java\jdk-12.0.1\bin </code>

After that go to your apk file location folder and use the following code,

```js

jarsigner -verify -verbose -certs my_application.apk

```  
This will tell you whether the apk is signed or not.


If you get any errors hop on to this [stackoverflow thread](https://stackoverflow.com/questions/7837952/what-is-the-command-to-list-the-available-avdnames) to solve it.

<strong>I wish people automated this stuff by setting all these environment variables at its appropriate place when installing the specific software. </strong>

Its too time confusing and frustrating to find out these were causing the problems and finding them in stack overflow and in forums.

As a beginner its a nightmare. But as I became more experienced it was not a big issue.
 

I have given you the list of all of them just use it whenever you need!

### Thank you for reading!!

<strong> <u>Check out my portfolio: </u> [Gautham's portfolio](https://gautham-portfolio.netlify.app/)</strong>

<strong> <u> Check out my blog: </u>[coding-magnified.tech](https://coding-magnified.tech)</strong>

If you want to appreciate my or support me, you can buy me a coffee with the link below,

<a href="https://www.buymeacoffee.com/XJvD4NhAK" target="_blank">
<img width="250px" height="100px"src="https://dev-to-uploads.s3.amazonaws.com/i/xwa28cylrit799s70lrs.png" alt="Buy Me a Coffee"</img>
</a>

### <u>My Other Articles: </u>

- [Universal CSS properties everyone must know](https://dev.to/gautham495/universal-css-properties-everyone-must-use-4kie)

- [Create-react-app](https://dev.to/gautham495/creating-a-new-react-app-with-create-react-app-4e9m)

- [Git for beginners](https://dev.to/gautham495/basic-git-knowledge-for-beginners-m4p)

 
- [Change headers in react with react-helmet](https://dev.to/gautham495/changing-headers-in-react-with-react-helmet-d0d)

- [Know How to apply box-shadow on all four sides.](https://dev.to/gautham495/know-how-to-apply-box-shadow-on-all-four-sides-43pn)
 
- [Simple CSS Selectors](https://dev.to/gautham495/simple-css-selectors-for-beginners-2i44).

- [CSS Pseudo Elements](https://dev.to/gautham495/css-pseudo-elements-for-beginners-53ob).